home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / adatutor / csparts / csparts.src < prev   
Text File  |  1996-01-30  |  453KB  |  11,227 lines

  1. --::::::::::
  2. --types.spc
  3. --::::::::::
  4. -- ***************************************************
  5. -- *                                                 *
  6. -- *  CS_Parts_Types                                 *  SPEC
  7. -- *                                                 *
  8. -- ***************************************************
  9. package CS_Parts_Types is
  10. --| Purpose
  11. --| Provide common type definitions for items in CS_Parts
  12. --| and useful conversion utilities.
  13. --|
  14. --| Initialization Exceptions (none)
  15. --| Notes
  16. --|    Not all MIL-HDBK-1804 PDL annotations are
  17. --| used in this package due to its simplicity.
  18. --|    No exceptions are raised in this package.
  19. --|
  20. --| Modifications
  21. --| 07/15/90  Rick Conn  Initial Design and Code
  22.  
  23.   type BYTE is range 16#0# .. 16#FF#;
  24.   for BYTE'SIZE use 8;
  25.  
  26.   -- ...................................................
  27.   -- .                                                 .
  28.   -- .  CS_Parts_Types.Convert                         .  SPEC
  29.   -- .                                                 .
  30.   -- ...................................................
  31.   function Convert (Item : in CHARACTER) return BYTE;
  32.   --| Purpose
  33.   --| Convert a CHARACTER into a BYTE.
  34.  
  35.   -- ...................................................
  36.   -- .                                                 .
  37.   -- .  CS_Parts_Types.Convert                         .  SPEC
  38.   -- .                                                 .
  39.   -- ...................................................
  40.   function Convert (Item : in INTEGER) return BYTE;
  41.   --| Purpose
  42.   --| Convert an INTEGER into a BYTE.  If the
  43.   --| INTEGER is greater than 255, only the low-order
  44.   --| BYTE is converted.
  45.  
  46.   -- ...................................................
  47.   -- .                                                 .
  48.   -- .  CS_Parts_Types.Convert                         .  SPEC
  49.   -- .                                                 .
  50.   -- ...................................................
  51.   function Convert (Item : in BYTE) return CHARACTER;
  52.   --| Purpose
  53.   --| Convert a BYTE into a CHARACTER.  If the most
  54.   --| significant bit of the BYTE is set, it is cleared
  55.   --| as the CHARACTER.
  56.  
  57.   -- ...................................................
  58.   -- .                                                 .
  59.   -- .  CS_Parts_Types.Convert                         .  SPEC
  60.   -- .                                                 .
  61.   -- ...................................................
  62.   function Convert (Item : in BYTE) return INTEGER;
  63.   --| Purpose
  64.   --| Convert a BYTE into a INTEGER.
  65.  
  66. end CS_Parts_Types;
  67. --::::::::::
  68. --console.spc
  69. --::::::::::
  70. -- *********************************************************
  71. -- *                                                       *
  72. -- *  Console                                              *  SPEC
  73. -- *                                                       *
  74. -- *********************************************************
  75. package Console is
  76. --| Purpose
  77. --| Console provides a set of I/O and screen control commands
  78. --| for either IBM PC computers employing the ANSI.SYS device
  79. --| driver or the VT100-compatible family of terminals.  By using
  80. --| this package, a programmer may manipulate the terminal screen
  81. --| regardless if it is an IBM PC with ANSI.SYS or a VT100 terminal.
  82. --|
  83. --| The console object runs in one of three modes:
  84. --|   TTY        All screen-oriented commands are disabled
  85. --|   VT100      All screen-oriented commands except display
  86. --|              color control (foreground and background)
  87. --|              are enabled
  88. --|   ANSI       All screen-oriented commands are enabled
  89. --| The default mode is TTY, and the mode of the console object
  90. --| can be changed at any time by calling the Set_Terminal
  91. --| routine.
  92. --|
  93. --| The output to the console object can be enabled or disabled
  94. --| by using the Enable_Output and Disable_Output routines.
  95. --| The Push and Pop routines can be used to preserve the current
  96. --| state of the console and restore the console to the previous
  97. --| state.
  98. --|
  99. --| Initialization Exceptions (none)
  100. --| Notes (none)
  101. --|
  102. --| Modifications
  103. --| 3/8/91  Richard Conn  Initial Release
  104.  
  105.   Max_Number_of_States : constant NATURAL := 10;
  106.   -- number of enable/disable states to the console; also,
  107.   -- number of Push calls before a State_Overflow exception
  108.  
  109.   type TERMINAL_KIND is (TTY,   -- no screen-oriented commands
  110.                          ANSI,  -- colors supported
  111.                          VT100  -- no colors
  112.                         );
  113.  
  114.   type ROW_NUMBER is new INTEGER range 1..24;
  115.   type COLUMN_NUMBER is new INTEGER range 1..80;
  116.  
  117.   type RENDITION is
  118.       (ALL_ATTRIBUTES_OFF,      -- ANSI.SYS or VT100
  119.        HIGH_INTENSITY,
  120.        BLINKING,
  121.        REVERSE_VIDEO,
  122.        FOREGROUND_BLACK,        -- ANSI.SYS only
  123.        FOREGROUND_RED,
  124.        FOREGROUND_GREEN,
  125.        FOREGROUND_YELLOW,
  126.        FOREGROUND_BLUE,
  127.        FOREGROUND_MAGENTA,
  128.        FOREGROUND_CYAN,
  129.        FOREGROUND_WHITE,
  130.        BACKGROUND_BLACK,
  131.        BACKGROUND_RED,
  132.        BACKGROUND_GREEN,
  133.        BACKGROUND_YELLOW,
  134.        BACKGROUND_BLUE,
  135.        BACKGROUND_MAGENTA,
  136.        BACKGROUND_CYAN,
  137.        BACKGROUND_WHITE);
  138.   for RENDITION'Size use INTEGER'Size;
  139.   for RENDITION use
  140.       (ALL_ATTRIBUTES_OFF      => 0,  -- ANSI.SYS or VT100
  141.        HIGH_INTENSITY          => 1,
  142.        BLINKING                => 5,
  143.        REVERSE_VIDEO           => 7,
  144.        FOREGROUND_BLACK        => 30, -- ANSI.SYS only
  145.        FOREGROUND_RED          => 31,
  146.        FOREGROUND_GREEN        => 32,
  147.        FOREGROUND_YELLOW       => 33,
  148.        FOREGROUND_BLUE         => 34,
  149.        FOREGROUND_MAGENTA      => 35,
  150.        FOREGROUND_CYAN         => 36,
  151.        FOREGROUND_WHITE        => 37,
  152.        BACKGROUND_BLACK        => 40,
  153.        BACKGROUND_RED          => 41,
  154.        BACKGROUND_GREEN        => 42,
  155.        BACKGROUND_YELLOW       => 43,
  156.        BACKGROUND_BLUE         => 44,
  157.        BACKGROUND_MAGENTA      => 45,
  158.        BACKGROUND_CYAN         => 46,
  159.        BACKGROUND_WHITE        => 47);
  160.  
  161.   type OVERFLOW_ACTION is  -- used for a Put(STRING)
  162.     (TRUNCATE_HEAD,          -- ABC becomes "BC"
  163.      TRUNCATE_TAIL,          -- ABC becomes "AB"
  164.      FILL_WITH_OVERFLOW_CHAR -- ABC becomes "**"
  165.     );
  166.  
  167.   type NUMERIC_OVERFLOW_ACTION is -- used for a Put(INTEGER)
  168.     (FILL_WITH_OVERFLOW_CHAR,  -- 123 becomes "**"
  169.      OUTPUT_FULL_NUMBER        -- 123 becomes "123"
  170.     );
  171.  
  172.   type JUSTIFICATION   is  -- used for a Put(STRING)
  173.     (LEFT_JUSTIFIED,         -- ABC becomes "ABC "
  174.      RIGHT_JUSTIFIED         -- ABC becomes " ABC"
  175.     );
  176.  
  177.   INPUT_ERROR : exception;  -- raised on invalid input
  178.   STATE_OVERFLOW : exception;
  179.       -- raised if the Max_Number_of_States is exceeded
  180.   STATE_UNDERFLOW : exception;
  181.       -- raised if too many Pop routine calls are made
  182.  
  183.   -- .................................................................
  184.   -- .                                                               .
  185.   -- .  Console.Set_Terminal                                         .  SPEC
  186.   -- .                                                               .
  187.   -- .................................................................
  188.   procedure Set_Terminal (New_Setting : in TERMINAL_KIND := TTY);
  189.   --| Purpose
  190.   --| Define the kind of user's terminal.  If this routine is not
  191.   --| called, TTY is assumed.
  192.   --|
  193.   --| Exceptions (none)
  194.   --| Notes (none)
  195.  
  196.   -- .................................................................
  197.   -- .                                                               .
  198.   -- .  Console.Enable_Output                                        .  SPEC
  199.   -- .                                                               .
  200.   -- .................................................................
  201.   procedure Enable_Output;
  202.   --| Purpose
  203.   --| Enable the output routines of the console object (affects current
  204.   --| state only).  These routines include Position_Cursor, Erase_Display,
  205.   --| Erase_Line, Set_Rendition, all the Put and Put_Line routines, and
  206.   --| New_Line.
  207.   --|
  208.   --| Exceptions (none)
  209.   --| Notes (none)
  210.  
  211.   -- .................................................................
  212.   -- .                                                               .
  213.   -- .  Console.Disable_Output                                       .  SPEC
  214.   -- .                                                               .
  215.   -- .................................................................
  216.   procedure Disable_Output;
  217.   --| Purpose
  218.   --| Disable the output routines of the console object (affects current
  219.   --| state only).  These routines include Position_Cursor, Erase_Display,
  220.   --| Erase_Line, Set_Rendition, all the Put and Put_Line routines, and
  221.   --| New_Line.
  222.   --|
  223.   --| Exceptions (none)
  224.   --| Notes (none)
  225.  
  226.   -- .................................................................
  227.   -- .                                                               .
  228.   -- .  Console.Push                                                 .  SPEC
  229.   -- .                                                               .
  230.   -- .................................................................
  231.   procedure Push;
  232.   --| Purpose
  233.   --| Increment to the next state (environment) of the console object.
  234.   --| All states are initialized to be enabled.  This routine permits,
  235.   --| for example, a console to be turned off for silent running and
  236.   --| then temporarily turned on for an error message display.  The
  237.   --| console object stays in this new state, which may be altered by
  238.   --| the Enable_Output and Disable_Output routines, until a Pop is
  239.   --| executed.
  240.   --|
  241.   --| Exceptions
  242.   --|   STATE_OVERFLOW -- raised if Max_Number_of_States is exceeded
  243.   --| Notes (none)
  244.  
  245.   -- .................................................................
  246.   -- .                                                               .
  247.   -- .  Console.Pop                                                  .  SPEC
  248.   -- .                                                               .
  249.   -- .................................................................
  250.   procedure Pop;
  251.   --| Purpose
  252.   --| Decrement to the previous state (environment) of the console object.
  253.   --| All states are initialized to be enabled.  See the Push routine
  254.   --| for more details.
  255.   --|
  256.   --| Exceptions
  257.   --|   STATE_UNDERFLOW -- raised if current state tries to drop below 0
  258.   --| Notes (none)
  259.  
  260.   -- .................................................................
  261.   -- .                                                               .
  262.   -- .  Console.Position_Cursor                                      .  SPEC
  263.   -- .                                                               .
  264.   -- .................................................................
  265.   procedure Position_Cursor (Row    : in ROW_NUMBER;
  266.                              Column : in COLUMN_NUMBER);
  267.   --| Purpose
  268.   --| Position the cursor to the indicated Row and Column.  Row 1,
  269.   --| Column 1 is the upper left corner of the screen.
  270.   --|
  271.   --| Exceptions (none)
  272.   --| Notes (none)
  273.  
  274.   -- .................................................................
  275.   -- .                                                               .
  276.   -- .  Console.Erase_Display                                        .  SPEC
  277.   -- .                                                               .
  278.   -- .................................................................
  279.   procedure Erase_Display;
  280.   --| Purpose
  281.   --| Erase the entire display and place the cursor at the home position.
  282.   --|
  283.   --| Exceptions (none)
  284.   --| Notes (none)
  285.  
  286.   -- .................................................................
  287.   -- .                                                               .
  288.   -- .  Console.Erase_Line                                           .  SPEC
  289.   -- .                                                               .
  290.   -- .................................................................
  291.   procedure Erase_Line;
  292.   --| Purpose
  293.   --| Erase from the cursor to the end of the line.
  294.   --|
  295.   --| Exceptions (none)
  296.   --| Notes (none)
  297.  
  298.   -- .................................................................
  299.   -- .                                                               .
  300.   -- .  Console.Set_Rendition                                        .  SPEC
  301.   -- .                                                               .
  302.   -- .................................................................
  303.   procedure Set_Rendition (New_Setting : in RENDITION);
  304.   --| Purpose
  305.   --| Add the indicated New_Setting to the current graphics display
  306.   --| rendition (default is ALL_ATTRIBUTES_OFF).  Calls to this procedure
  307.   --| are cumulative until all attributes are turned off.
  308.   --|
  309.   --| Exceptions (none)
  310.   --|
  311.   --| Notes
  312.   --|   Color selections are ignored on a VT100 compatible terminal.
  313.  
  314.   -- .................................................................
  315.   -- .                                                               .
  316.   -- .  Console.Put                                                  .  SPEC
  317.   -- .                                                               .
  318.   -- .................................................................
  319.   procedure Put (Item : in CHARACTER);
  320.   procedure Put (Item : in STRING);
  321.   --| Purpose
  322.   --| Output a character or a string to the console.
  323.   --|
  324.   --| Exceptions (none)
  325.   --| Notes (none)
  326.  
  327.   -- .................................................................
  328.   -- .                                                               .
  329.   -- .  Console.Put                                                  .  SPEC
  330.   -- .                                                               .
  331.   -- .................................................................
  332.   procedure Put
  333.     ( Item           : in STRING;
  334.       Field_Width    : in NATURAL;
  335.       On_Overflow    : in OVERFLOW_ACTION := TRUNCATE_TAIL;
  336.       On_Underflow   : in JUSTIFICATION   := LEFT_JUSTIFIED;
  337.       Fill_Char      : in CHARACTER       := ' ';
  338.       Overflow_Char  : in CHARACTER       := '*' );
  339.   --| Purpose
  340.   --| Output a string to the console in a field of a given
  341.   --| Field_Width.
  342.   --|     If Item is shorter than Field_Width,
  343.   --| the On_Underflow flag takes effect, justifying Item
  344.   --| in the field as indicated using the Fill_Char.
  345.   --|     If Item is longer than Field_Width, the On_Overflow
  346.   --| flag takes effect, either truncating Item on the left or
  347.   --| right or filling the field with the Overflow_Char.
  348.   --|
  349.   --| Exceptions (none)
  350.   --| Notes (none)
  351.  
  352.   -- .................................................................
  353.   -- .                                                               .
  354.   -- .  Console.Put                                                  .  SPEC
  355.   -- .                                                               .
  356.   -- .................................................................
  357.   procedure Put (Item          : in INTEGER;
  358.                  Width         : in NATURAL;
  359.                  On_Overflow   : in NUMERIC_OVERFLOW_ACTION
  360.                                    := FILL_WITH_OVERFLOW_CHAR;
  361.                  Overflow_Char : in CHARACTER := '*');
  362.   --| Purpose
  363.   --| Output an integer to the console.  It will be placed in a
  364.   --| field that is Width characters long.  Width of 0 fits the
  365.   --| INTEGER exactly.  If the resulting sequence of characters
  366.   --| has fewer than Width characters, then leading spaces are
  367.   --| first output to make up the difference.  If the resulting
  368.   --| sequence of characters has more than Width characters,
  369.   --| then the On_Overflow flag takes effect.
  370.   --|
  371.   --| Exceptions (none)
  372.   --| Notes (none)
  373.  
  374.   -- .................................................................
  375.   -- .                                                               .
  376.   -- .  Console.Put                                                  .  SPEC
  377.   -- .                                                               .
  378.   -- .................................................................
  379.   procedure Put (Item          : in FLOAT;
  380.                  Fore          : in NATURAL;
  381.                  Aft           : in NATURAL;
  382.                  On_Overflow   : in NUMERIC_OVERFLOW_ACTION
  383.                                    := FILL_WITH_OVERFLOW_CHAR;
  384.                  Overflow_Char : in CHARACTER := '*');
  385.   --| Purpose
  386.   --| Output a floating point number to the console.  Fore is the
  387.   --| number of characters to be displayed before the decimal point,
  388.   --| and Aft is the number of characters to be displayed after the
  389.   --| decimal point.  Item's value appears as follows:
  390.   --|
  391.   --|        Fore Aft      fields
  392.   --|        ---- ---      (Fore=4, Aft=3)
  393.   --|        nnnn.nnn      if Item is positive
  394.   --|        -nnn.nnn      if Item is negative
  395.   --|        ********      if overflow with defaults
  396.   --|
  397.   --|     If Item is negative, a leading minus sign, which counts as
  398.   --| one of the characters in the Fore field, is output.
  399.   --|     If -1.0 < Item < 1.0, then -0 or 0 is output in the Fore
  400.   --| field.
  401.   --|     If the number of digits required to display Item in the Fore
  402.   --| field exceeds the value of Fore (i.e., is too big), the
  403.   --| On_Overflow flag takes effect, either overriding Fore or filling
  404.   --| the field with the Overflow_Char.
  405.   --|
  406.   --| Exceptions (none)
  407.   --| Notes (none)
  408.  
  409.   -- .................................................................
  410.   -- .                                                               .
  411.   -- .  Console.Put                                                  .  SPEC
  412.   -- .                                                               .
  413.   -- .................................................................
  414.   procedure Put (Item : in FLOAT;
  415.                  Fore : in NATURAL := 2;
  416.                  Aft  : in NATURAL := 2;
  417.                  Exp  : in NATURAL := 3);
  418.   --| Purpose
  419.   --| Output a floating point number in scientific notation
  420.   --| to the console.  Fore is the number of characters to be
  421.   --| displayed before the decimal point (only one digit and
  422.   --| a sign are displayed, so rest of Fore characters are
  423.   --| leading spaces), Aft is the number of characters to be
  424.   --| displayed after the decimal point, and Exp is the number
  425.   --| of characters in the exponent.  Item's value appears as:
  426.   --|
  427.   --|          -- ---- ---      (Fore=2, Aft=4, Exp=3)
  428.   --|           n.nnnnE+nn      if Item is positive
  429.   --|          -n.nnnnE+nn      if Item is negative
  430.   --|
  431.   --|     The Fore field will always contain a single digit with
  432.   --| an optional minus sign.  If Fore > 2, leading spaces are
  433.   --| prefixed to the output.  Hence, Put(-123.0, 4, 2, 3) outputs
  434.   --| "  -1.23E+02".
  435.   --|     Exp is the size of the field for the number after the "E".
  436.   --| This field always includes a leading sign (see -123.0 example
  437.   --| above).
  438.   --|
  439.   --| Exceptions (none)
  440.   --| Notes (none)
  441.  
  442.   -- .................................................................
  443.   -- .                                                               .
  444.   -- .  Console.Put_Line                                             .  SPEC
  445.   -- .                                                               .
  446.   -- .................................................................
  447.   procedure Put_Line (Item : in STRING);
  448.   --| Purpose
  449.   --| Output a string followed by a new line to the console.
  450.   --|
  451.   --| Exceptions (none)
  452.   --| Notes (none)
  453.  
  454.   -- .................................................................
  455.   -- .                                                               .
  456.   -- .  Console.New_Line                                             .  SPEC
  457.   -- .                                                               .
  458.   -- .................................................................
  459.   procedure New_Line;
  460.   --| Purpose
  461.   --| Output a new line to the console.
  462.   --|
  463.   --| Exceptions (none)
  464.   --| Notes (none)
  465.  
  466.   -- .................................................................
  467.   -- .                                                               .
  468.   -- .  Console.Get                                                  .  SPEC
  469.   -- .                                                               .
  470.   -- .................................................................
  471.   procedure Get
  472.     ( Item          : out CHARACTER);
  473.   procedure Get
  474.     ( Item          : out INTEGER);
  475.   procedure Get
  476.     ( Item          : out FLOAT);
  477.   --| Purpose
  478.   --| Get views the Console input as a stream and
  479.   --| returns the next Item of the appropriate type
  480.   --| from it.
  481.   --|
  482.   --| Exceptions
  483.   --|   Input_Error  raised if the next item
  484.   --|                in the stream is not of the
  485.   --|                correct type when translated
  486.   --|                from the characters or if the
  487.   --|                translation process encounters
  488.   --|                an error condition
  489.   --|
  490.   --| Notes
  491.   --|   If the Item is of type INTEGER or FLOAT, Get
  492.   --| skips over whitespace characters (blank, tab, new
  493.   --| line) first and then starts translating at the
  494.   --| first non-white character encountered.
  495.   --|   If the Item is of type CHARACTER, Get returns
  496.   --| the next character, whitespace or not.
  497.  
  498.   -- .................................................................
  499.   -- .                                                               .
  500.   -- .  Console.Get_Line                                             .  SPEC
  501.   -- .                                                               .
  502.   -- .................................................................
  503.   procedure Get_Line
  504.     ( Item           : out STRING;
  505.       Last           : out NATURAL );
  506.   --| Purpose
  507.   --| Get_Line reads a line from the console.
  508.   --|
  509.   --| Exceptions (none)
  510.   --| Notes (none)
  511.  
  512. end Console;
  513. --::::::::::
  514. --bintree.spc
  515. --::::::::::
  516. -- ********************************************************
  517. -- *                                                      *
  518. -- *  BINARY_TREES_PKG                                    *  SPEC
  519. -- *                                                      *
  520. -- ********************************************************
  521. generic
  522.     type VALUE_TYPE is private;
  523.     with function Difference(P, Q: VALUE_TYPE) return integer is <>;
  524.         -- Must return a value > 0 if P > Q, 0 if P = Q, and less than
  525.         -- zero otherwise.
  526. package Binary_Trees_Pkg is
  527. --| Purpose
  528. --| This package is an efficient implementation of unbalanced binary trees.
  529. --| These trees have the following properties:
  530. --|
  531. --|  1. Inserting a value is cheap (log n Differences per insertion).
  532. --|  2. Finding a value is cheap (log n Differences per querey).
  533. --|  3. Can iterate over the values in sorted order in linear time.
  534. --|  4. Space overhead is moderate (2 "pointers" per value stored).
  535. --|
  536. --| They are thus useful both for sorting sequences of indeterminate size
  537. --| and for lookup tables.
  538. --| 
  539. --| Initialization Exceptions (none)
  540. --| Notes
  541. --| The following example shows how to use this package where nodes in
  542. --| the tree are labeled with a String_Type value (for which a natural
  543. --| Difference function is not available).
  544. --|-
  545. --|     package SP renames String_Pkg;
  546. --| 
  547. --|     type my_Value is record
  548. --|       label: SP.string_type;
  549. --|       value: integer;
  550. --|     end record;
  551. --| 
  552. --|     function differ_label(P, Q: SP.string_type) return integer is
  553. --|     begin
  554. --|       if SP."<"(P, Q) then return -1;
  555. --|       elsif SP."<"(Q, P) then return 1;
  556. --|       else return 0;
  557. --|       end if;
  558. --|     end differ_label;
  559. --| 
  560. --|     package my_Tree is new Binary_Trees_pkg(my_Value, differ_Label);
  561. --| 
  562. --| Note that the required Difference function may be easily written in terms
  563. --| of "<" if that is available, but that frequently two comparisons must
  564. --| be done for each Difference.  However, both comparisons would have
  565. --| to be done internally by this package for every instantiation if the
  566. --| generic parameter were "<" instead of Difference.
  567. --| 
  568. --| PERFORMANCE
  569. --|
  570. --| Every node can be visited in the tree in linear time.  The cost
  571. --| of creating an iterator is small and independent of the size
  572. --| of the tree.
  573. --| 
  574. --| Recognizing that comparing values can be expensive, this package
  575. --| takes a Difference function as a generic parameter.  If it took
  576. --| a comparison function such as "<", then two comparisons would be
  577. --| made per node visited during a search of the tree.  Of course this
  578. --| is more costly when "<" is a trivial operation, but in those cases,
  579. --| Difference can be bound to "-" and the overhead in negligable.
  580. --| 
  581. --| Two different kinds of iterators are provided.  The first is the 
  582. --| commonly used set of functions Make_Iter, More, and Next.  The second
  583. --| is a generic procedure called Visit.  The generic parameter to Visit is
  584. --| a procedure which is called once for each value in the tree.  Visit
  585. --| is more difficult to use and results in code that is not quite as clear,
  586. --| but its overhead is about 20% of the More/Next style iterator.  It
  587. --| is therefore recommended for use only in time critical inner loops.
  588. --|
  589. --| Modifications
  590. --| Author: Bill Toscano and Michael Gordon, Intermetrics, Inc.
  591.  
  592. -- Exceptions --
  593.  
  594.   Duplicate_Value: exception;
  595.       -- Raised on attempt to insert a duplicate node into a tree.
  596.  
  597.   Not_Found: exception;
  598.       -- Raised on attempt to find a node that is not in a tree.
  599.  
  600.   No_More: exception;
  601.       -- Raised on attempt to bump an iterator that has already scanned the
  602.       -- entire tree.
  603.  
  604.   Out_Of_Order: exception;
  605.       -- Raised if a problem in the ordering of a tree is detected.
  606.  
  607.   Invalid_Tree: exception;
  608.       -- Value is not a tree or was not properly initialized.
  609.  
  610. -- Types --
  611.  
  612.   type SCAN_KIND is (INORDER, PREORDER, POSTORDER);
  613.   -- Used to specify the order in which values should be scanned from a tree:
  614.   --
  615.   -- inorder: Left, Node, Right (nodes visited in increasing order)
  616.   -- preorder: Node, Left, Right (top down)
  617.   -- postorder: Left, Right, Node (bottom up)
  618.  
  619.   type TREE is private;
  620.   type ITERATOR is private;
  621.  
  622. -- Operations --
  623.  
  624.   -- .....................................................
  625.   -- .                                                   .
  626.   -- .  BINARY_TREES_PKG.CREATE                          .  SPEC
  627.   -- .                                                   .
  628.   -- .....................................................
  629.   Function Create return TREE;
  630.   --| Purpose
  631.   --| Create and return an empty tree.  Note that this allocates
  632.   --| a small amount of storage which can only be reclaimed through 
  633.   --| a call to Destroy.
  634.   --|
  635.   --| Exceptions (none)
  636.   --| Notes (none)
  637.  
  638.   -- .....................................................
  639.   -- .                                                   .
  640.   -- .  BINARY_TREES_PKG.INSERT                          .  SPEC
  641.   -- .                                                   .
  642.   -- .....................................................
  643.   Procedure Insert (V: VALUE_TYPE;
  644.                     T: TREE);
  645.   --| Purpose
  646.   --| Insert V into T in the proper place.  If a value equal
  647.   --| to V (according to the Difference function) is already contained
  648.   --| in the tree, the exception Duplicate_Value is raised.
  649.   --| Caution: Since this package does not attempt to balance trees as
  650.   --| values are inserted, it is important to remember that inserting
  651.   --| values in sorted order will create a degenerate tree, where search
  652.   --| and insertion is proportional to the N instead of to Log N.  If
  653.   --| this pattern is common, use the Balanced_Tree function below.
  654.   --|
  655.   --| Exceptions
  656.   --|   Duplicate_Value
  657.   --|   Invalid_Tree
  658.   --|
  659.   --| Notes (none)
  660.  
  661.   -- .....................................................
  662.   -- .                                                   .
  663.   -- .  BINARY_TREES_PKG.INSERT_IF_NOT_FOUND             .  SPEC
  664.   -- .                                                   .
  665.   -- .....................................................
  666.   procedure Insert_if_not_Found (V         : VALUE_TYPE;
  667.                                  T         : TREE;
  668.                                  Found     : out BOOLEAN;
  669.                                  Duplicate : out VALUE_TYPE);
  670.   --| Purpose
  671.   --| Insert V into T in the proper place.  If a value equal
  672.   --| to V (according to the Difference function) is already contained
  673.   --| in the tree, Found will be True and Duplicate will be the duplicate
  674.   --| value.  This might be a sequence of values with the same key, and
  675.   --| V can then be added to the sequence.
  676.   --|
  677.   --| Exceptions
  678.   --|   Invalid_Tree.
  679.   --|
  680.   --| Notes (none)
  681.  
  682.   -- .....................................................
  683.   -- .                                                   .
  684.   -- .  BINARY_TREES_PKG.REPLACE_IF_FOUND                .  SPEC
  685.   -- .                                                   .
  686.   -- .....................................................
  687.   procedure Replace_if_Found (V         : VALUE_TYPE;
  688.                               T         : TREE;
  689.                               Found     : out BOOLEAN;
  690.                               Old_Value : out VALUE_TYPE);
  691.   --| Purpose
  692.   --| Search for V in T.  If found, replace the old value with V,
  693.   --| and return Found => True, Old_Value => the old value.  Otherwise,
  694.   --| simply insert V into T and return Found => False.
  695.   --|
  696.   --| Exceptions
  697.   --|   Invalid_Tree.
  698.   --|
  699.   --| Notes (none)
  700.  
  701.   -- .....................................................
  702.   -- .                                                   .
  703.   -- .  BINARY_TREES_PKG.DESTROY                         .  SPEC
  704.   -- .                                                   .
  705.   -- .....................................................
  706.   procedure Destroy (T: in out TREE);
  707.   --| Purpose
  708.   --| The space allocated to T is reclaimed.  The space occupied by
  709.   --| the values stored in T is not however, recovered.
  710.   --|
  711.   --| Exceptions (none)
  712.   --| Notes (none)
  713.  
  714.   -- .....................................................
  715.   -- .                                                   .
  716.   -- .  BINARY_TREES_PKG.DESTROY_DEEP                    .  SPEC
  717.   -- .                                                   .
  718.   -- .....................................................
  719.   generic
  720.     with procedure Free_Value(V: in out VALUE_TYPE) is <>;
  721.   procedure Destroy_Deep (T: in out TREE);
  722.   --| Purpose
  723.   --| The space allocated to T is reclaimed.  The values stored
  724.   --| in T are reclaimed using Free_Value, and the tree nodes themselves
  725.   --| are then reclaimed (in a single walk of the tree).
  726.   --|
  727.   --| Exceptions (none)
  728.   --| Notes (none)
  729.  
  730.   -- .....................................................
  731.   -- .                                                   .
  732.   -- .  BINARY_TREES_PKG.BALANCED_TREE                   .  SPEC
  733.   -- .                                                   .
  734.   -- .....................................................
  735.   generic
  736.     with function Next_Value return VALUE_TYPE is <>;
  737.     -- Each call to this procedure should return the next value to be
  738.     -- inserted into the balanced tree being created.  If necessary,
  739.     -- this function should check that each value is greater than the
  740.     -- previous one, and raise Out_of_Order if necessary.  If values
  741.     -- are not returned in strictly increasing order, the results are
  742.     -- unpredictable.
  743.   Function Balanced_Tree (Count: NATURAL) return TREE;
  744.   --| Purpose
  745.   --| Create a balanced tree by calling next_Value Count times.
  746.   --| Each time Next_Value is called, it must return a value that compares
  747.   --| greater than the preceeding value.  This function is useful for balancing
  748.   --| an existing tree (next_Value iterates over the unbalanced tree) or
  749.   --| for creating a balanced tree when reading data from a file which is
  750.   --| already sorted.
  751.   --|
  752.   --| Exceptions (none)
  753.   --| Notes (none)
  754.  
  755.   -- .....................................................
  756.   -- .                                                   .
  757.   -- .  BINARY_TREES_PKG.COPY_TREE                       .  SPEC
  758.   -- .                                                   .
  759.   -- .....................................................
  760.   generic
  761.     with function Copy_Value(V: VALUE_TYPE) return VALUE_TYPE is <>;
  762.     -- This function is called to copy a value from the old tree to the
  763.     -- new tree.
  764.   Function Copy_Tree (T: TREE) return TREE;
  765.   --| Purpose
  766.   --| Create a balanced tree that is a copy of the tree T.
  767.   --| The exception Invalid_Tree is raised if T is not a valid tree.
  768.   --|
  769.   --| Exceptions
  770.   --|   Invalid_Tree
  771.   --|
  772.   --| Notes (none)
  773.  
  774.   -- .....................................................
  775.   -- .                                                   .
  776.   -- .  BINARY_TREES_PKG.IS_EMPTY                        .  SPEC
  777.   -- .                                                   .
  778.   -- .....................................................
  779.   Function Is_Empty (T: TREE) return BOOLEAN;
  780.   --| Purpose
  781.   --| Return TRUE iff T is an empty tree or if T was not initialized.
  782.   --|
  783.   --| Exceptions (none)
  784.   --| Notes (none)
  785.  
  786.   -- .....................................................
  787.   -- .                                                   .
  788.   -- .  BINARY_TREES_PKG.FIND                            .  SPEC
  789.   -- .                                                   .
  790.   -- .....................................................
  791.   Function Find (V: VALUE_TYPE;
  792.                  T: TREE) return VALUE_TYPE;
  793.   --| Purpose
  794.   --| Search T for a value that matches V.  The matching value is
  795.   --| returned.  If no matching value is found, the exception Not_Found
  796.   --| is raised.
  797.   --|
  798.   --| Exceptions
  799.   --|   Not_Found
  800.   --|   Invalid_Tree
  801.   --|
  802.   --| Notes (none)
  803.  
  804.   -- .....................................................
  805.   -- .                                                   .
  806.   -- .  BINARY_TREES_PKG.FIND                            .  SPEC
  807.   -- .                                                   .
  808.   -- .....................................................
  809.   Procedure Find (V     : VALUE_TYPE;
  810.                   T     : TREE;
  811.                   Found : out BOOLEAN;
  812.                   Match : out VALUE_TYPE);
  813.   --| Purpose
  814.   --| Search T for a value that matches V.  On return, if Found is
  815.   --| TRUE then the matching value is returned in Match.  Otherwise, Found
  816.   --| is FALSE and Match is undefined.
  817.   --|
  818.   --| Exceptions
  819.   --|   Invalid_Tree;
  820.   --|
  821.   --| Notes (none)
  822.  
  823.   -- .....................................................
  824.   -- .                                                   .
  825.   -- .  BINARY_TREES_PKG.IS_FOUND                        .  SPEC
  826.   -- .                                                   .
  827.   -- .....................................................
  828.   function Is_Found (V: VALUE_TYPE;
  829.                      T: TREE) return BOOLEAN;
  830.   --| Purpose
  831.   --| Return TRUE iff V is found in T.
  832.   --|
  833.   --| Exceptions
  834.   --|   Invalid_Tree
  835.   --|
  836.   --| Notes (none)
  837.  
  838.   -- .....................................................
  839.   -- .                                                   .
  840.   -- .  BINARY_TREES_PKG.SIZE                            .  SPEC
  841.   -- .                                                   .
  842.   -- .....................................................
  843.   function Size (T: TREE) return NATURAL; 
  844.   --| Purpose
  845.   --| Return the number of values stored in T.
  846.   --|
  847.   --| Exceptions (none)
  848.   --| Notes (none)
  849.  
  850.   -- .....................................................
  851.   -- .                                                   .
  852.   -- .  BINARY_TREES_PKG.VISIT                           .  SPEC
  853.   -- .                                                   .
  854.   -- .....................................................
  855.   generic
  856.     with procedure Process(V: VALUE_TYPE) is <>;
  857.   procedure Visit (T     : TREE;
  858.                    Order : SCAN_KIND);
  859.   --| Purpose
  860.   --| Invoke Process(V) for each value V in T.  The nodes are visited
  861.   --| in the order specified by Order.  Although more limited than using
  862.   --| an iterator, this function is also much faster.
  863.   --|
  864.   --| Exceptions
  865.   --|   Invalid_Tree
  866.   --|
  867.   --| Notes (none)
  868.  
  869.   -- .....................................................
  870.   -- .                                                   .
  871.   -- .  BINARY_TREES_PKG.MAKE_ITER                       .  SPEC
  872.   -- .                                                   .
  873.   -- .....................................................
  874.   function Make_Iter (T: TREE) return ITERATOR;
  875.   --| Purpose
  876.   --| Create an iterator over a tree.
  877.   --|
  878.   --| Exceptions
  879.   --|  Invalid_Tree
  880.   --|
  881.   --| Notes (none)
  882.  
  883.   -- .....................................................
  884.   -- .                                                   .
  885.   -- .  BINARY_TREES_PKG.MORE                            .  SPEC
  886.   -- .                                                   .
  887.   -- .....................................................
  888.   function More (I: ITERATOR) return BOOLEAN;
  889.   --| Purpose
  890.   --| Return TRUE iff unscanned nodes remain in the tree being
  891.   --| scanned by I.
  892.   --|
  893.   --| Exceptions (none)
  894.   --| Notes (none)
  895.  
  896.   -- .....................................................
  897.   -- .                                                   .
  898.   -- .  BINARY_TREES_PKG.NEXT                            .  SPEC
  899.   -- .                                                   .
  900.   -- .....................................................
  901.   procedure Next (I: in out ITERATOR;
  902.                   V: out VALUE_TYPE);
  903.   --| Purpose
  904.   --| Return the next value in the tree being scanned by I.
  905.   --| The exception No_More is raised if there are no more values to scan.
  906.   --|
  907.   --| Exceptions
  908.   --|   No_More
  909.   --|
  910.   --| Notes (none)
  911.  
  912. private
  913.  
  914.   type NODE;
  915.   type NODE_PTR is access NODE;
  916.  
  917.   type NODE is 
  918.     record
  919.       Value : VALUE_TYPE;
  920.       Less  : NODE_PTR;
  921.       More  : NODE_PTR;
  922.     end record;
  923.  
  924.   type TREE_HEADER is 
  925.     record
  926.       Count : NATURAL := 0;
  927.       Root  : NODE_PTR := Null;
  928.     end record;
  929.  
  930.   type TREE is access TREE_HEADER;
  931.  
  932.   type ITER_STATE is (LEFT, MIDDLE, RIGHT, DONE);
  933.  
  934.   type ITERATOR_RECORD;
  935.   type ITERATOR is access ITERATOR_RECORD;
  936.  
  937.   type ITERATOR_RECORD is
  938.     record
  939.       State   : ITER_STATE;
  940.       Parent  : ITERATOR;
  941.       Subtree : NODE_PTR;
  942.     end record;
  943.  
  944. end Binary_Trees_Pkg;
  945. --::::::::::
  946. --bit.spc
  947. --::::::::::
  948. -- ***************************************************************
  949. -- *                                                             *
  950. -- *  BIT_FUNCTIONS                                              *  SPEC
  951. -- *                                                             *
  952. -- ***************************************************************
  953. package Bit_Functions is
  954. --| Purpose
  955. --|   This package allows the Ada programmer to manipulate the bits
  956. --|   within an object of type INTEGER.  The bits are numbers from
  957. --|   the right to the left, starting with number zero.
  958. --| 
  959. --|           +------------------------+
  960. --|           +  15 14 13 ...  3 2 1 0 !
  961. --|           +------------------------+
  962. --| 
  963. --|      In each routine, the number of bits being manipulated
  964. --|      is NBITS.  START_AT identifies the right most bit of NBITS field.
  965. --| 
  966. --|      e.g.
  967. --|           ...  6 5 4 3 2 1 0
  968. --|                    X X X         nbits = 3
  969. --|                                  start_at = 2
  970. --| 
  971. --| Initialization Exceptions (none)
  972. --| Notes
  973. --|    Not all MIL-HDBK-1804 PDL annotations are
  974. --| used in this package due to its simplicity.
  975. --|    No exceptions are raised by this package.
  976. --|
  977. --| Modifications
  978. --| Author: Freeman Moore, TI
  979.  
  980.   -- ..................................................................
  981.   -- .                                                                .
  982.   -- .  BIT_FUNCTIONS.BIT_EXTRACT                                     .  SPEC
  983.   -- .                                                                .
  984.   -- ..................................................................
  985.   function Bit_Extract (Item, Start_At, Nbits : INTEGER) return INTEGER;
  986.   --| Purpose
  987.   --| Return the bit field extracted from ITEM, as a signed integer.
  988.  
  989.   -- ..................................................................
  990.   -- .                                                                .
  991.   -- .  BIT_FUNCTIONS.UBIT_EXTRACT                                    .  SPEC
  992.   -- .                                                                .
  993.   -- ..................................................................
  994.   function Ubit_Extract (Item, Start_At, Nbits : INTEGER) return INTEGER;
  995.   --| Purpose
  996.   --| Return the bit field extracted from ITEM, unsigned integer.
  997.  
  998.   -- ..................................................................
  999.   -- .                                                                .
  1000.   -- .  BIT_FUNCTIONS.BIT_INSERT                                      .  SPEC
  1001.   -- .                                                                .
  1002.   -- ..................................................................
  1003.   function Bit_Insert (This_Item, Nbits, Into_Item, Start_At : INTEGER)
  1004.       return INTEGER;
  1005.   --| Purpose
  1006.   --| Insert NBITS from THIS_ITEM into the object INTO_ITEM,
  1007.   --| with the rightmost bit identified by START_AT.
  1008.  
  1009.   -- ..................................................................
  1010.   -- .                                                                .
  1011.   -- .  BIT_FUNCTIONS.BIT_REMOVE                                      .  SPEC
  1012.   -- .                                                                .
  1013.   -- ..................................................................
  1014.   function Bit_Remove (Item, Start_At, Nbits : INTEGER) return INTEGER;
  1015.   --| Purpose
  1016.   --| BIT_REMOVE will zero out NBITS of ITEM at position START_AT.
  1017.  
  1018.   -- ..................................................................
  1019.   -- .                                                                .
  1020.   -- .  BIT_FUNCTIONS.SHIFT_LEFT                                      .  SPEC
  1021.   -- .                                                                .
  1022.   -- ..................................................................
  1023.   function Shift_Left (Item, Nbits : INTEGER) return INTEGER;
  1024.   --| Purpose
  1025.   --| Return ITEM shifted left by NBITS.
  1026.  
  1027.   -- ..................................................................
  1028.   -- .                                                                .
  1029.   -- .  BIT_FUNCTIONS.SHIFT_RIGHT                                     .  SPEC
  1030.   -- .                                                                .
  1031.   -- ..................................................................
  1032.   function Shift_Right (Item, Nbits : INTEGER) return INTEGER;
  1033.   --| Purpose
  1034.   --| Return ITEM shifted right by NBITS.
  1035.  
  1036.   -- ..................................................................
  1037.   -- .                                                                .
  1038.   -- .  BIT_FUNCTIONS.BIT_AND                                         .  SPEC
  1039.   -- .                                                                .
  1040.   -- ..................................................................
  1041.   function Bit_AND (Word1, Word2 : INTEGER) return INTEGER;
  1042.   --| Purpose
  1043.   --| Return the AND of the two objects.
  1044.  
  1045.   -- ..................................................................
  1046.   -- .                                                                .
  1047.   -- .  BIT_FUNCTIONS.BIT_OR                                          .  SPEC
  1048.   -- .                                                                .
  1049.   -- ..................................................................
  1050.   function Bit_OR (Word1, Word2 : INTEGER) return INTEGER;
  1051.   --| Purpose
  1052.   --| Return the OR of the two objects.
  1053.  
  1054.   -- ..................................................................
  1055.   -- .                                                                .
  1056.   -- .  BIT_FUNCTIONS.BIT_MASK                                        .  SPEC
  1057.   -- .                                                                .
  1058.   -- ..................................................................
  1059.   function Bit_Mask (Nbits : INTEGER) return INTEGER;
  1060.   --| Purpose
  1061.   --| Return an object with NBITS of one bits, right justified.
  1062.  
  1063. end Bit_Functions;
  1064. --::::::::::
  1065. --bplustre.spc
  1066. --::::::::::
  1067. -- **********************************************************
  1068. -- *                                                        *
  1069. -- *  BP_Tree                                               *  SPEC
  1070. -- *                                                        *
  1071. -- **********************************************************
  1072. generic
  1073.   type KEY_TYPE is limited private;
  1074.   type NON_KEY_ITEM_TYPE is limited private;
  1075.   type NON_KEY_ITEM_CONTAINER is limited private;
  1076.   with function Empty
  1077.       (This_Non_Key_Item_Container : in NON_KEY_ITEM_CONTAINER)
  1078.     return Boolean is <>;
  1079.   with procedure Assign
  1080.       (To_Non_Key_Item_Container   : in out NON_KEY_ITEM_CONTAINER;
  1081.        From_Non_Key_Item_Container : in     NON_KEY_ITEM_CONTAINER)
  1082.     is <>;
  1083.   with procedure Insert
  1084.       (Container    : in out NON_KEY_ITEM_CONTAINER;
  1085.        Non_Key_Item : in     NON_KEY_ITEM_TYPE      ) is <>;
  1086.   with procedure Delete
  1087.       (Container    : in out NON_KEY_ITEM_CONTAINER;
  1088.        Non_Key_Item : in     NON_KEY_ITEM_TYPE      ) is <>;    
  1089.   with procedure Destroy_Contents
  1090.       (This_Non_Key_Item_Container : in out NON_KEY_ITEM_CONTAINER)
  1091.     is <>;
  1092.     -- This procedure must destroy everything in the container
  1093.     -- in preparation for the destruction of the container itself.
  1094.   with procedure Assign (Target_Key : in out KEY_TYPE;
  1095.                          Source_Key : in     KEY_TYPE) is <>;
  1096.   with function Less_Than (First_Key  : in KEY_TYPE;                       
  1097.                            Second_Key : in KEY_TYPE)
  1098.     return Boolean is <>;
  1099.   with function Equal (First_Key  : in KEY_TYPE;
  1100.                        Second_Key : in KEY_TYPE)
  1101.     return Boolean is <>;
  1102. package BP_Tree is
  1103. --| Purpose
  1104. --| Implement a B+ Tree class of objects.
  1105. --|
  1106. --| Initialization Exceptions (none)
  1107. --| Notes (none)
  1108. --|
  1109. --| Modifications
  1110. --| Author: William Thomas Wolfe, Clemson University
  1111.  
  1112. -- *******************************************************
  1113. -- This software is part of the Clemson University
  1114. -- Computer Science Department's Ada Software
  1115. -- Repository, and is copyrighted (C) 1989 by
  1116. -- Clemson University.  Permission to copy without
  1117. -- fee all or part of this software is granted,
  1118. -- provided that the copies are not made or
  1119. -- distributed for direct commercial advantage, and
  1120. -- that this copyright notice is not deleted or
  1121. -- modified.  To copy otherwise, or to republish,
  1122. -- requires a fee and/or specific permission.
  1123. -- *******************************************************
  1124.  
  1125.   type B_PLUS_TREE is limited private;
  1126.  
  1127.   Key_Does_Not_Exist_In_This_B_Plus_Tree            : EXCEPTION;
  1128.   No_Preceding_Key_Exists_In_This_B_Plus_Tree       : EXCEPTION;
  1129.   No_Following_Key_Exists_In_This_B_Plus_Tree       : EXCEPTION;
  1130.   No_Keys_Currently_Exist_In_This_Empty_B_Plus_Tree : EXCEPTION;
  1131.  
  1132.   type POINTER_TO_B_PLUS_TREE is access B_PLUS_TREE;
  1133.  
  1134.   -- ....................................................
  1135.   -- .                                                  .
  1136.   -- .  BP_Tree.Destroy                                 .  SPEC
  1137.   -- .                                                  .
  1138.   -- ....................................................
  1139.   procedure Destroy
  1140.       (Targeted_Object : in out POINTER_TO_B_PLUS_TREE);
  1141.   --| Purpose
  1142.   --| Unlike Unchecked_Deallocation, this procedure will properly
  1143.   --| destroy the B_Plus_Tree pointed to.
  1144.   --|
  1145.   --| Exceptions (none)
  1146.   --| Notes (none)
  1147.  
  1148.   -- ....................................................
  1149.   -- .                                                  .
  1150.   -- .  BP_Tree.Insert_Item                             .  SPEC
  1151.   -- .                                                  .
  1152.   -- ....................................................
  1153.   procedure Insert_Item
  1154.       (Targeted_B_Plus_Tree : in out B_PLUS_TREE;
  1155.        Key_Value            : in     KEY_TYPE;
  1156.        Non_Key_Information  : in     NON_KEY_ITEM_TYPE);
  1157.   --| Purpose
  1158.   --| Insert an element into the Targeted_B_Plus_Tree.
  1159.   --|
  1160.   --| Exceptions (none)
  1161.   --| Notes (none)
  1162.  
  1163.   -- ....................................................
  1164.   -- .                                                  .
  1165.   -- .  BP_Tree.Delete_Item                             .  SPEC
  1166.   -- .                                                  .
  1167.   -- ....................................................
  1168.   procedure Delete_Item
  1169.       (Targeted_B_Plus_Tree : in out B_PLUS_TREE;
  1170.        Key_Value            : in     KEY_TYPE;
  1171.        Non_Key_Information  : in     NON_KEY_ITEM_TYPE);
  1172.   --| Purpose
  1173.   --| Remove an element from the Targeted_B_Plus_Tree.
  1174.   --|
  1175.   --| Exceptions
  1176.   --|   Key_Does_Not_Exist_In_This_B_Plus_Tree 
  1177.   --|   No_Keys_Currently_Exist_In_This_Empty_B_Plus_Tree
  1178.   --|
  1179.   --| Notes (none)
  1180.  
  1181.   -- ....................................................
  1182.   -- .                                                  .
  1183.   -- .  BP_Tree.Key_Exists                              .  SPEC
  1184.   -- .                                                  .
  1185.   -- ....................................................
  1186.   function Key_Exists (Targeted_B_Plus_Tree : in B_PLUS_TREE;
  1187.                        Search_Key           : in KEY_TYPE)
  1188.     return BOOLEAN;
  1189.   --| Purpose
  1190.   --| Return TRUE iff Search_Key is found in Targeted_B_Plus_Tree.
  1191.   --|
  1192.   --| Exceptions (none)
  1193.   --| Notes (none)
  1194.  
  1195.   -- ....................................................
  1196.   -- .                                                  .
  1197.   -- .  BP_Tree.Number_Of_Keys_Stored                   .  SPEC
  1198.   -- .                                                  .
  1199.   -- ....................................................
  1200.   function Number_Of_Keys_Stored
  1201.       (Targeted_B_Plus_Tree : in B_PLUS_TREE)
  1202.     return NATURAL;
  1203.   --| Purpose
  1204.   --| Return the Number_of_Keys_Stored in Targeted_B_Plus_Tree.
  1205.   --|
  1206.   --| Exceptions (none)
  1207.   --| Notes (none)
  1208.  
  1209.   -- ....................................................
  1210.   -- .                                                  .
  1211.   -- .  BP_Tree.Get_Item_Container                      .  SPEC
  1212.   -- .                                                  .
  1213.   -- ....................................................
  1214.   function Get_Item_Container
  1215.       (Targeted_B_Plus_Tree : in B_PLUS_TREE;
  1216.        Search_Key           : in KEY_TYPE    )
  1217.     return NON_KEY_ITEM_CONTAINER;
  1218.   --| Purpose
  1219.   --| Return the NON_KEY_ITEM_CONTAINER associated with the
  1220.   --| Search_Key in Targeted_B_Plus_Tree.
  1221.   --|
  1222.   --| Exceptions
  1223.   --|   Key_Does_Not_Exist_In_This_B_Plus_Tree 
  1224.   --|   No_Keys_Currently_Exist_In_This_Empty_B_Plus_Tree
  1225.   --|
  1226.   --| Notes
  1227.   --| This procedure involves copying the entire container.  If
  1228.   --| your NON_KEY_ITEM_TYPE is quite large, it may be advisable
  1229.   --| to implement it as a pointer to the "real" structures,
  1230.   --| thus reducing the copying burden per instance of the
  1231.   --| NON_KEY_ITEM_TYPE to that of a single pointer.
  1232.  
  1233.   -- ....................................................
  1234.   -- .                                                  .
  1235.   -- .  BP_Tree.Get_First_Key                           .  SPEC
  1236.   -- .                                                  .
  1237.   -- ....................................................
  1238.   function Get_First_Key (Targeted_B_Plus_Tree : in B_PLUS_TREE)
  1239.     return KEY_TYPE;
  1240.   --| Purpose
  1241.   --| Return the first KEY_TYPE in Targeted_B_Plus_Tree.
  1242.   --|
  1243.   --| Exceptions
  1244.   --|   No_Keys_Currently_Exist_In_This_Empty_B_Plus_Tree
  1245.   --|
  1246.   --| Notes (none)
  1247.  
  1248.   -- ....................................................
  1249.   -- .                                                  .
  1250.   -- .  BP_Tree.Get_Last_Key                            .  SPEC
  1251.   -- .                                                  .
  1252.   -- ....................................................
  1253.   function Get_Last_Key (Targeted_B_Plus_Tree : in B_PLUS_TREE)
  1254.     return KEY_TYPE;
  1255.   --| Purpose
  1256.   --| Return the last KEY_TYPE in Targeted_B_Plus_Tree.
  1257.   --|
  1258.   --| Exceptions
  1259.   --|   No_Keys_Currently_Exist_In_This_Empty_B_Plus_Tree
  1260.   --|
  1261.   --| Notes (none)
  1262.  
  1263.   -- ....................................................
  1264.   -- .                                                  .
  1265.   -- .  BP_Tree.A_Preceding_Key_Exists                  .  SPEC
  1266.   -- .                                                  .
  1267.   -- ....................................................
  1268.   function A_Preceding_Key_Exists
  1269.       (Targeted_B_Plus_Tree : in B_PLUS_TREE;
  1270.        Search_Key           : in KEY_TYPE)
  1271.     return Boolean;
  1272.   --| Purpose
  1273.   --| Determine if a key exists in the Targeted_B_Plus_Tree
  1274.   --| before the Search_Key.
  1275.   --|
  1276.   --| Exceptions
  1277.   --|   Key_Does_Not_Exist_In_This_B_Plus_Tree 
  1278.   --|   No_Keys_Currently_Exist_In_This_Empty_B_Plus_Tree
  1279.   --|
  1280.   --| Notes (none)
  1281.  
  1282.   -- ....................................................
  1283.   -- .                                                  .
  1284.   -- .  BP_Tree.Get_Preceding_Key                       .  SPEC
  1285.   -- .                                                  .
  1286.   -- ....................................................
  1287.   function Get_Preceding_Key
  1288.       (Targeted_B_Plus_Tree : in B_PLUS_TREE;
  1289.        Search_Key           : in KEY_TYPE)
  1290.     return KEY_TYPE;
  1291.   --| Purpose
  1292.   --| Obtain the preceding key in the Targeted_B_Plus_Tree
  1293.   --| before the Search_Key.
  1294.   --|
  1295.   --| Exceptions
  1296.   --|   Key_Does_Not_Exist_In_This_B_Plus_Tree 
  1297.   --|   No_Preceding_Key_Exists_In_This_B_Plus_Tree
  1298.   --|   No_Keys_Currently_Exist_In_This_Empty_B_Plus_Tree
  1299.   --|
  1300.   --| Notes (none)
  1301.  
  1302.   -- ....................................................
  1303.   -- .                                                  .
  1304.   -- .  BP_Tree.A_Following_Key_Exists                  .  SPEC
  1305.   -- .                                                  .
  1306.   -- ....................................................
  1307.   function A_Following_Key_Exists
  1308.       (Targeted_B_Plus_Tree : in B_PLUS_TREE;
  1309.        Search_Key           : in KEY_TYPE)
  1310.     return Boolean;
  1311.   --| Purpose
  1312.   --| Determine if a key exists in the Targeted_B_Plus_Tree after
  1313.   --| the Search_Key.
  1314.   --|
  1315.   --| Exceptions
  1316.   --|   Key_Does_Not_Exist_In_This_B_Plus_Tree 
  1317.   --|   No_Keys_Currently_Exist_In_This_Empty_B_Plus_Tree
  1318.   --|
  1319.   --| Notes (none)
  1320.  
  1321.   -- ....................................................
  1322.   -- .                                                  .
  1323.   -- .  BP_Tree.Get_Following_Key                       .  SPEC
  1324.   -- .                                                  .
  1325.   -- ....................................................
  1326.   function Get_Following_Key
  1327.       (Targeted_B_Plus_Tree : in B_PLUS_TREE;
  1328.        Search_Key           : in KEY_TYPE)
  1329.     return KEY_TYPE;
  1330.   --| Purpose
  1331.   --| Obtain the following key in the Targeted_B_Plus_Tree
  1332.   --| before the Search_Key.
  1333.   --|
  1334.   --| Exceptions
  1335.   --|   Key_Does_Not_Exist_In_This_B_Plus_Tree 
  1336.   --|   No_Following_Key_Exists_In_This_B_Plus_Tree
  1337.   --|   No_Keys_Currently_Exist_In_This_Empty_B_Plus_Tree
  1338.   --|
  1339.   --| Notes (none)
  1340.  
  1341.   -- ....................................................
  1342.   -- .                                                  .
  1343.   -- .  BP_Tree.Delete_Key                              .  SPEC
  1344.   -- .                                                  .
  1345.   -- ....................................................
  1346.   procedure Delete_Key
  1347.       (Targeted_B_Plus_Tree : in out B_PLUS_TREE;
  1348.        Search_Key           : in     KEY_TYPE);
  1349.   --| Purpose
  1350.   --| Remove a Search_Key from the Targeted_B_Plus_Tree.
  1351.   --|
  1352.   --| Exceptions
  1353.   --|   Key_Does_Not_Exist_In_This_B_Plus_Tree 
  1354.   --|   No_Keys_Currently_Exist_In_This_Empty_B_Plus_Tree
  1355.   --|
  1356.   --| Notes
  1357.   --| The NON_KEY_ITEM_CONTAINER associated with this key will
  1358.   --| be emptied via the Destroy_Contents procedure.
  1359.  
  1360.   -- ....................................................
  1361.   -- .                                                  .
  1362.   -- .  BP_Tree.Exchange                                .  SPEC
  1363.   -- .                                                  .
  1364.   -- ....................................................
  1365.   procedure Exchange (First_B_Plus_Tree  : in out B_PLUS_TREE;
  1366.                       Second_B_Plus_Tree : in out B_PLUS_TREE);
  1367.   --| Purpose
  1368.   --| Exchanges the values of First_B_PLUS_TREE and
  1369.   --| Second_B_PLUS_TREE in O(1) time.
  1370.   --|
  1371.   --| Exceptions (none)
  1372.   --| Notes (none)
  1373.  
  1374.   -- ....................................................
  1375.   -- .                                                  .
  1376.   -- .  BP_Tree.Assign                                  .  SPEC
  1377.   -- .                                                  .
  1378.   -- ....................................................
  1379.   procedure Assign (To_B_Plus_Tree   : in out B_PLUS_TREE;
  1380.                     From_B_Plus_Tree : in     B_PLUS_TREE);
  1381.   --| Purpose
  1382.   --| Replaces the contents of To_B_Plus_Tree with
  1383.   --| From_B_Plus_Tree.
  1384.   --|
  1385.   --| Exceptions (none)
  1386.   --| Notes (none)
  1387.  
  1388.   -- ....................................................
  1389.   -- .                                                  .
  1390.   -- .  BP_Tree.Destroy                                 .  SPEC
  1391.   -- .                                                  .
  1392.   -- ....................................................
  1393.   procedure Destroy (Targeted_B_Plus_Tree : in out B_PLUS_TREE);
  1394.   --| Purpose
  1395.   --| Destroys all keys and all associated containers
  1396.   --| and renders the tree Empty.
  1397.   --|
  1398.   --| Exceptions (none)
  1399.   --| Notes (none)
  1400.  
  1401.   -- ....................................................
  1402.   -- .                                                  .
  1403.   -- .  BP_Tree.Destroy                                 .  SPEC
  1404.   -- .                                                  .
  1405.   -- ....................................................
  1406.   function Empty (Targeted_B_Plus_Tree: in B_PLUS_TREE)
  1407.     return Boolean;
  1408.   --| Purpose
  1409.   --| Determine if Targeted_B_Plus_Tree is empty.
  1410.   --|
  1411.   --| Exceptions (none)
  1412.   --| Notes (none)
  1413.  
  1414. private
  1415.    type B_PLUS_TREE_DESCRIPTOR;
  1416.    type B_PLUS_TREE is access B_PLUS_TREE_DESCRIPTOR;   
  1417. end BP_Tree;
  1418. --::::::::::
  1419. --cisc.spc
  1420. --::::::::::
  1421. -- *******************************************
  1422. -- *                                         *
  1423. -- *  CASE_INSENSITIVE_STRING_COMPARISON     *  SPEC
  1424. -- *                                         *
  1425. -- *******************************************
  1426. package Case_Insensitive_String_Comparison is
  1427. --| Purpose
  1428. --| This package provides a complete set of comparison functions on strings
  1429. --| where case is NOT important ("a" = "A").
  1430. --|
  1431. --| Initialization Exceptions (none)
  1432. --| Notes (none)
  1433. --|
  1434. --| Modifications
  1435. --| Programmer: Michael Gordon
  1436.  
  1437.   -- .................................................
  1438.   -- .                                               .
  1439.   -- .  CASE_INSENSITIVE_STRING_COMPARISION.TOUPPER  .  SPEC
  1440.   -- .                                               .
  1441.   -- .................................................
  1442.   function ToUpper (C: CHARACTER) return CHARACTER;
  1443.   --| Purpose
  1444.   --|          If C is in 'a'..'z' return the corresponding upper case
  1445.   --| character.  Otherwise, return C.  This is implemented by a table
  1446.   --| lookup for speed.
  1447.   --|
  1448.   --| Exceptions (none)
  1449.   --| Notes (none)
  1450.  
  1451.   -- .................................................
  1452.   -- .                                               .
  1453.   -- .  CASE_INSENSITIVE_STRING_COMPARISION.UPCASE   .  SPEC
  1454.   -- .                                               .
  1455.   -- .................................................
  1456.   procedure UpCase (S: in out STRING);
  1457.   --| Purpose
  1458.   --|        Convert all characters in S to upper case.
  1459.   --|
  1460.   --| Exceptions (none)
  1461.   --| Notes (none)
  1462.     pragma inline(UpCase);
  1463.  
  1464.   -- .................................................
  1465.   -- .                                               .
  1466.   -- .  CASE_INSENSITIVE_STRING_COMPARISION.UPCASE   .  SPEC
  1467.   -- .                                               .
  1468.   -- .................................................
  1469.   function UpCase (S: STRING) return STRING;
  1470.   --| Purpose
  1471.   --|          Make a copy of S, convert all lower case characters to upper
  1472.   --| case and return the copy.
  1473.   --|
  1474.   --| Exceptions (none)
  1475.   --| Notes (none)
  1476.  
  1477.   -- .................................................
  1478.   -- .                                               .
  1479.   -- .  CASE_INSENSITIVE_STRING_COMPARISION.TOLOWER  .  SPEC
  1480.   -- .                                               .
  1481.   -- .................................................
  1482.   function ToLower (C: CHARACTER) return CHARACTER;
  1483.   --| Purpose
  1484.   --|          If C is in 'A'..'Z' return the corresponding lower case
  1485.   --| character.  Otherwise, return C.  This is implemented by a table
  1486.   --| lookup for speed.
  1487.   --|
  1488.   --| Exceptions (none)
  1489.   --| Notes (none)
  1490.  
  1491.   -- .................................................
  1492.   -- .                                               .
  1493.   -- .  CASE_INSENSITIVE_STRING_COMPARISION.DOWNCASE .  SPEC
  1494.   -- .                                               .
  1495.   -- .................................................
  1496.   procedure DownCase (S: in out STRING);
  1497.   --| Purpose
  1498.   --|          Convert all characters in S to lower case.
  1499.   --|
  1500.   --| Exceptions (none)
  1501.   --| Notes (none)
  1502.     pragma inline(DownCase);
  1503.  
  1504.   -- .................................................
  1505.   -- .                                               .
  1506.   -- .  CASE_INSENSITIVE_STRING_COMPARISION.DOWNCASE .  SPEC
  1507.   -- .                                               .
  1508.   -- .................................................
  1509.   function DownCase (S: STRING) return STRING;
  1510.   --| Purpose
  1511.   --|          Make a copy of S, convert all lower case characters to lower
  1512.   --| case and return the copy.
  1513.   --|
  1514.   --| Exceptions (none)
  1515.   --| Notes (none)
  1516.  
  1517.   -- .................................................
  1518.   -- .                                               .
  1519.   -- .  CASE_INSENSITIVE_STRING_COMPARISION.COMPARE  .  SPEC
  1520.   -- .                                               .
  1521.   -- .................................................
  1522.   function Compare (P, Q: STRING) return INTEGER;
  1523.   --| Purpose
  1524.   --|          Return an integer less than zero if P < Q, zero if P = Q, and
  1525.   --| an integer greater than zero if P > Q.
  1526.   --|
  1527.   --| Exceptions (none)
  1528.   --| Notes (none)
  1529.  
  1530.   -- .................................................
  1531.   -- .                                               .
  1532.   -- .  CASE_INSENSITIVE_STRING_COMPARISION.EQUAL    .  SPEC
  1533.   -- .                                               .
  1534.   -- .................................................
  1535.   function Equal (P, Q: STRING) return BOOLEAN;
  1536.   --| Purpose
  1537.   --|        Return TRUE iff P = Q.
  1538.   --|
  1539.   --| Exceptions (none)
  1540.   --| Notes (none)
  1541.  
  1542.   -- .................................................
  1543.   -- .                                               .
  1544.   -- .  CASE_INSENSITIVE_STRING_COMPARISION.LESS     .  SPEC
  1545.   -- .                                               .
  1546.   -- .................................................
  1547.   function Less (P, Q: STRING) return BOOLEAN;
  1548.   --| Purpose
  1549.   --|        Return TRUE iff P < Q.
  1550.   --|
  1551.   --| Exceptions (none)
  1552.   --| Notes (none)
  1553.  
  1554.   -- ......................................................
  1555.   -- .                                                    .
  1556.   -- .  CASE_INSENSITIVE_STRING_COMPARISION.LESS_OR_EQUAL .  SPEC
  1557.   -- .                                                    .
  1558.   -- ......................................................
  1559.   function Less_or_Equal (P, Q: STRING) return BOOLEAN;
  1560.   --| Purpose
  1561.   --|        Return TRUE iff P <= Q.
  1562.   --|
  1563.   --| Exceptions (none)
  1564.   --| Notes (none)
  1565.  
  1566.   -- .................................................
  1567.   -- .                                               .
  1568.   -- .  CASE_INSENSITIVE_STRING_COMPARISION.GREATER  .  SPEC
  1569.   -- .                                               .
  1570.   -- .................................................
  1571.   function Greater (P, Q: STRING) return BOOLEAN;
  1572.   --| Purpose
  1573.   --|        Return TRUE iff P > Q.
  1574.   --|
  1575.   --| Exceptions (none)
  1576.   --| Notes (none)
  1577.  
  1578.   -- ..........................................................
  1579.   -- .                                                        .
  1580.   -- .  CASE_INSENSITIVE_STRING_COMPARISION.GREATER_OR_EQUAL  .  SPEC
  1581.   -- .                                                        .
  1582.   -- ..........................................................
  1583.   function Greater_or_Equal (P, Q: STRING) return BOOLEAN;
  1584.   --| Purpose
  1585.   --|        Return TRUE iff P >= Q.
  1586.   --|
  1587.   --| Exceptions (none)
  1588.   --| Notes (none)
  1589.  
  1590. private
  1591.  
  1592.     pragma inline (Equal, Less, Less_or_Equal, Greater, Greater_or_Equal);
  1593.     pragma inline (ToUpper, ToLower);
  1594.  
  1595. end Case_Insensitive_String_Comparison;
  1596. --::::::::::
  1597. --cli.spc
  1598. --::::::::::
  1599. -- **************************************
  1600. -- *                                    *
  1601. -- * CLI (Command Line Interface)       * SPEC
  1602. -- *                                    *
  1603. -- **************************************
  1604. package CLI is
  1605.  
  1606. --| Purpose
  1607. --|   CLI is a package which implements a Command
  1608. --| Line Interface.  It mirrors the UNIX/C
  1609. --| command line interface, providing an argument
  1610. --| count and the arguments themselves.
  1611. --|
  1612. --| Initialization Exceptions (none)
  1613. --|
  1614. --| Notes
  1615. --|   Compiler limit on string length and dynamic memory.
  1616. --|   INITIALIZE must be called once, and only once, during
  1617. --| the execution of the main Ada proc.
  1618. --|
  1619. --| Modifications
  1620. --|  2/25/88  Richard Conn    Initial Version
  1621. --|  5/12/89  Richard Conn    Review and Upgrade
  1622. --|  4/11/90  Richard Conn    MIL-HDBK-1804 Annotations and
  1623. --|                           Meridian Ada Interface Added
  1624.    
  1625.   -- ...................................
  1626.   -- .                                 .
  1627.   -- . CLI.INITIALIZE                  . SPEC
  1628.   -- .                                 .
  1629.   -- ...................................
  1630.   procedure Initialize (Program_Name        : in STRING;
  1631.                         Command_Line_Prompt : in STRING);
  1632.   --| Purpose
  1633.   --|   Initialize this package.  This routine must be called
  1634.   --| before any other routines or objects are called or referenced.
  1635.   --|
  1636.   --| Exceptions (none)
  1637.   --|
  1638.   --| Notes
  1639.   --|   CALL THIS PROCEDURE ONLY ONE TIME
  1640.  
  1641.   -- ...................................
  1642.   -- .                                 .
  1643.   -- . CLI.ARGC (Argument Count)       . SPEC
  1644.   -- .                                 .
  1645.   -- ...................................
  1646.   function ArgC return NATURAL;
  1647.   --| Purpose
  1648.   --|   Return the number (1 to N) of command line arguments.
  1649.   --| ARGC is at least 1 because the name of the program or
  1650.   --| process is always ARGV(0).
  1651.   --|
  1652.   --| Exceptions (none)
  1653.   --| Notes (none)
  1654.  
  1655.   -- ...................................
  1656.   -- .                                 .
  1657.   -- . CLI.ARGV (Argument Value)       . SPEC
  1658.   -- .                                 .
  1659.   -- ...................................
  1660.   function ArgV (Index : in NATURAL) return STRING;
  1661.   --| Purpose
  1662.   --|   Return the INDEXth (0 <= INDEX < ARGC) command line
  1663.   --| argument.  Example: if ARGC = 1, ARGV(0) is the only
  1664.   --| valid argument string.  ARGV(0) is always the name of
  1665.   --| the program or process.
  1666.   --|
  1667.   --| Exceptions
  1668.   --|   INVALID_INDEX     raised if Index >= ARGC
  1669.   --|
  1670.   --| Notes (none)
  1671.  
  1672.   INVALID_INDEX    : exception;
  1673.   UNEXPECTED_ERROR : exception;  -- raised anytime
  1674.    
  1675. end CLI;
  1676. --::::::::::
  1677. --cset.spc
  1678. --::::::::::
  1679. -- ******************************************************
  1680. -- *                                                    *
  1681. -- *  Character_Set                                     *  SPEC
  1682. -- *                                                    *
  1683. -- ******************************************************
  1684. package Character_Set is
  1685. --| Purpose
  1686. --| These routines test for the following subsets of package
  1687. --| ASCII:
  1688. --| Routine              Subset tested for
  1689. --| =======              =================
  1690. --| ALPHA                'a'..'z' | 'A'..'Z'
  1691. --| ALPHA_NUMERIC        ALPHA | '0'..'9'
  1692. --| CONTROL              < ' ' | DEL
  1693. --| DIGIT                '0'..'9'
  1694. --| GRAPHIC              ' ' < ch < DEL (does not include space)
  1695. --| HEXADECIMAL          DIGIT | 'A'..'F' | 'a'..'f'
  1696. --| LOWER                'a'..'z'
  1697. --| PRINTABLE            GRAPHIC | ' '
  1698. --| PUNCTUATION          GRAPHIC and not ALPHA_NUMERIC
  1699. --| SPACE                HT | LF | VT | FF | CR | ' '
  1700. --| UPPER                'A'..'Z'
  1701. --|
  1702. --| Initialization Exceptions (none)
  1703. --| Notes
  1704. --|     Most of the "functions" are actually arrays indexed by
  1705. --| CHARACTER, so they are remarkably efficient.
  1706. --|    Not all MIL-HDBK-1804 PDL annotations are
  1707. --| used in this package due to its simplicity.
  1708. --|
  1709. --| Modifications
  1710. --| Author: Richard Conn, TI
  1711. --| Modified by: Joseph M. Orost, Concurrent Computer Corp
  1712.  
  1713.   use  ASCII;
  1714.  
  1715.   type BIT_ARRAY is array (CHARACTER) of BOOLEAN;
  1716.   pragma PACK (BIT_ARRAY);
  1717.  
  1718.   -- ...................................................
  1719.   -- .                                                 .
  1720.   -- .  Character_Set.Is_Alpha                         .  SPEC
  1721.   -- .                                                 .
  1722.   -- ...................................................
  1723.   Is_Alpha         : constant BIT_ARRAY :=
  1724.       BIT_ARRAY'('a' .. 'z' => TRUE,
  1725.                  'A' .. 'Z' => TRUE,
  1726.                  others => FALSE);
  1727.  
  1728.   -- ...................................................
  1729.   -- .                                                 .
  1730.   -- .  Character_Set.Is_Alpha_Numeric                 .  SPEC
  1731.   -- .                                                 .
  1732.   -- ...................................................
  1733.   Is_Alpha_Numeric : constant BIT_ARRAY :=
  1734.     BIT_ARRAY'('a' .. 'z' => TRUE,
  1735.                'A' .. 'Z' => TRUE,
  1736.                '0' .. '9' => TRUE,
  1737.                others => FALSE   );
  1738.  
  1739.   -- ...................................................
  1740.   -- .                                                 .
  1741.   -- .  Character_Set.Is_Control                       .  SPEC
  1742.   -- .                                                 .
  1743.   -- ...................................................
  1744.   Is_Control       : constant BIT_ARRAY :=
  1745.     BIT_ARRAY'(NUL .. US => TRUE,
  1746.                DEL => TRUE,
  1747.                others => FALSE);
  1748.  
  1749.   -- ...................................................
  1750.   -- .                                                 .
  1751.   -- .  Character_Set.Is_Digit                         .  SPEC
  1752.   -- .                                                 .
  1753.   -- ...................................................
  1754.   Is_Digit         : constant BIT_ARRAY :=
  1755.     BIT_ARRAY'('0' .. '9' => TRUE,
  1756.                others => FALSE);
  1757.  
  1758.   -- ...................................................
  1759.   -- .                                                 .
  1760.   -- .  Character_Set.Is_Graphic                       .  SPEC
  1761.   -- .                                                 .
  1762.   -- ...................................................
  1763.   Is_Graphic       : constant BIT_ARRAY :=
  1764.     BIT_ARRAY'('!' .. '~' => TRUE,
  1765.                others => FALSE);
  1766.  
  1767.   -- ...................................................
  1768.   -- .                                                 .
  1769.   -- .  Character_Set.Is_Hexadecimal                   .  SPEC
  1770.   -- .                                                 .
  1771.   -- ...................................................
  1772.   Is_Hexadecimal   : constant BIT_ARRAY :=
  1773.     BIT_ARRAY'('0' .. '9' => TRUE,
  1774.                'A' .. 'F' => TRUE,
  1775.                'a' .. 'f' => TRUE,
  1776.                others => FALSE   );
  1777.  
  1778.   -- ...................................................
  1779.   -- .                                                 .
  1780.   -- .  Character_Set.Is_Lower                         .  SPEC
  1781.   -- .                                                 .
  1782.   -- ...................................................
  1783.   Is_Lower         : constant BIT_ARRAY :=
  1784.     BIT_ARRAY'('a' .. 'z' => TRUE,
  1785.                others => FALSE);
  1786.  
  1787.   -- ...................................................
  1788.   -- .                                                 .
  1789.   -- .  Character_Set.Is_Printable                     .  SPEC
  1790.   -- .                                                 .
  1791.   -- ...................................................
  1792.   Is_Printable     : constant BIT_ARRAY :=
  1793.     BIT_ARRAY'(' ' .. '~' => TRUE,
  1794.                others => FALSE);
  1795.  
  1796.   -- ...................................................
  1797.   -- .                                                 .
  1798.   -- .  Character_Set.Is_Punctuation                   .  SPEC
  1799.   -- .                                                 .
  1800.   -- ...................................................
  1801.   Is_Punctuation   : constant BIT_ARRAY :=
  1802.     BIT_ARRAY'('!' .. '/' => TRUE,
  1803.                ':' .. '@' => TRUE,
  1804.                '[' .. '`' => TRUE,
  1805.                '{' .. '~' => TRUE,
  1806.                others => FALSE   );
  1807.  
  1808.   -- ...................................................
  1809.   -- .                                                 .
  1810.   -- .  Character_Set.Is_Space                         .  SPEC
  1811.   -- .                                                 .
  1812.   -- ...................................................
  1813.   Is_Space         : constant BIT_ARRAY :=
  1814.     BIT_ARRAY'(HT  => TRUE,
  1815.                LF  => TRUE,
  1816.                VT  => TRUE,
  1817.                FF  => TRUE,
  1818.                CR  => TRUE,
  1819.                ' ' => TRUE,
  1820.                others => FALSE);
  1821.  
  1822.   -- ...................................................
  1823.   -- .                                                 .
  1824.   -- .  Character_Set.Is_Upper                         .  SPEC
  1825.   -- .                                                 .
  1826.   -- ...................................................
  1827.   Is_Upper         : constant BIT_ARRAY :=
  1828.     BIT_ARRAY'('A' .. 'Z' => TRUE,
  1829.                others => FALSE);
  1830.  
  1831.   type TRANSLATION_ARRAY is array (CHARACTER) of CHARACTER;
  1832.   pragma PACK (TRANSLATION_ARRAY);
  1833.  
  1834.   -- ...................................................
  1835.   -- .                                                 .
  1836.   -- .  Character_Set.Lower                            .  SPEC
  1837.   -- .                                                 .
  1838.   -- ...................................................
  1839.   Lower            : constant TRANSLATION_ARRAY :=
  1840.   --| Notes
  1841.   --|   LOWER can be used in place of TO_LOWER (Ada won't
  1842.   --| allow overloading of an object and a procedure).
  1843.     (NUL, SOH, STX, ETX, EOT, ENQ, ACK, BEL, BS , HT ,
  1844.      LF , VT , FF , CR , SO , SI , DLE, DC1, DC2, DC3,
  1845.      DC4, NAK, SYN, ETB, CAN, EM , SUB, ESC, FS , GS ,
  1846.      RS , US , ' ', '!', '"', ASCII.SHARP, '$', '%', '&', ''',
  1847.      '(', ')', '*', '+', ',', '-', '.', '/', '0', '1',
  1848.      '2', '3', '4', '5', '6', '7', '8', '9', ':', ';',
  1849.      '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e',
  1850.      'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
  1851.      'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  1852.      'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c',
  1853.      'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
  1854.      'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
  1855.      'x', 'y', 'z', '{', '|', '}', '~', DEL);
  1856.  
  1857.   -- ...................................................
  1858.   -- .                                                 .
  1859.   -- .  Character_Set.To_Lower                         .  SPEC
  1860.   -- .                                                 .
  1861.   -- ...................................................
  1862.   function  To_Lower (Ch  : in CHARACTER) return CHARACTER;
  1863.   procedure To_Lower (Ch  : in out CHARACTER);
  1864.   procedure To_Lower (Str : in out STRING);
  1865.  
  1866.   -- ...................................................
  1867.   -- .                                                 .
  1868.   -- .  Character_Set.Upper                            .  SPEC
  1869.   -- .                                                 .
  1870.   -- ...................................................
  1871.   Upper            : constant TRANSLATION_ARRAY :=
  1872.   --| Notes
  1873.   --|   UPPER can be used in place of TO_UPPER.
  1874.   --|
  1875.     (NUL, SOH, STX, ETX, EOT, ENQ, ACK, BEL, BS , HT ,
  1876.      LF , VT , FF , CR , SO , SI , DLE, DC1, DC2, DC3,
  1877.      DC4, NAK, SYN, ETB, CAN, EM , SUB, ESC, FS , GS ,
  1878.      RS , US , ' ', '!', '"', ASCII.SHARP, '$', '%', '&', ''',
  1879.      '(', ')', '*', '+', ',', '-', '.', '/', '0', '1',
  1880.      '2', '3', '4', '5', '6', '7', '8', '9', ':', ';',
  1881.      '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E',
  1882.      'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  1883.      'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
  1884.      'Z', '[', '\', ']', '^', '_', '`', 'A', 'B', 'C',
  1885.      'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  1886.      'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  1887.      'X', 'Y', 'Z', '{', '|', '}', '~', DEL);
  1888.  
  1889.   -- ...................................................
  1890.   -- .                                                 .
  1891.   -- .  Character_Set.To_Upper                         .  SPEC
  1892.   -- .                                                 .
  1893.   -- ...................................................
  1894.   function  To_Upper (Ch  : in CHARACTER) return CHARACTER;
  1895.   procedure To_Upper (Ch  : in out CHARACTER);
  1896.   procedure To_Upper (Str : in out STRING);
  1897.  
  1898.   subtype CONTROL_CHARACTER_NAME_2 is STRING (1 .. 2);
  1899.   subtype CONTROL_CHARACTER_NAME_3 is STRING (1 .. 3);
  1900.  
  1901.   -- ...................................................
  1902.   -- .                                                 .
  1903.   -- .  Character_Set.CC_Name_2                        .  SPEC
  1904.   -- .                                                 .
  1905.   -- ...................................................
  1906.   function  CC_Name_2 (Ch : CHARACTER)
  1907.     return CONTROL_CHARACTER_NAME_2;
  1908.   --| Purpose
  1909.   --| Returns Ch as a two-character string.  If Ch is a control
  1910.   --| character, the string contains a caret (^) followed by
  1911.   --| the control character letter (e.g., ^H for ASCII.BS).
  1912.   --| If Ch is not a control character, the string contains a
  1913.   --| leading space and the character.
  1914.  
  1915.   -- ...................................................
  1916.   -- .                                                 .
  1917.   -- .  Character_Set.CC_Name_3                        .  SPEC
  1918.   -- .                                                 .
  1919.   -- ...................................................
  1920.   function  CC_Name_3 (Ch : CHARACTER)
  1921.     return CONTROL_CHARACTER_NAME_3;
  1922.   --| Purpose
  1923.   --| Returns Ch as a three-character string.  If Ch is a control
  1924.   --| character, the string contains the name given in ASCII (e.g.,
  1925.   --| "BS " for ^H).  If Ch is not a control character, the string
  1926.   --| contains two leading spaces and the character.
  1927.  
  1928. end Character_Set;
  1929. --::::::::::
  1930. --cssc.spc
  1931. --::::::::::
  1932. -- ********************************************************
  1933. -- *                                                      *
  1934. -- *  Case_Sensitive_String_Comparison                    *  SPEC
  1935. -- *                                                      *
  1936. -- ********************************************************
  1937. package Case_Sensitive_String_Comparison is
  1938. --| Purpose
  1939. --| This package provides a complete set of comparison
  1940. --| functions on strings where case is important ("a" /= "A").
  1941. --| In most cases these have the same effect as the Ada
  1942. --| predefined operators.  However, using this package
  1943. --| makes it easier to substitute case-insensitive comparison
  1944. --| later.
  1945. --|
  1946. --| Initialization Exceptions (none)
  1947. --| Notes
  1948. --|    No exceptions are raised by any method, so the MIL-HDBK-1804
  1949. --| annotation requirements are reduced.
  1950. --|
  1951. --| Modifications
  1952. --| Author: Michael Gordon, Intermetrics
  1953.  
  1954.   -- ...................................................
  1955.   -- .                                                 .
  1956.   -- .  Case_Sensitive_String_Comparison.Compare       .  SPEC
  1957.   -- .                                                 .
  1958.   -- ...................................................
  1959.   function Compare (P, Q: STRING) return INTEGER;
  1960.   --| Purpose
  1961.   --| Return an integer less than zero if P < Q, zero if
  1962.   --| P = Q, and an integer greater than zero if P > Q.
  1963.  
  1964.   -- ...................................................
  1965.   -- .                                                 .
  1966.   -- .  Case_Sensitive_String_Comparison.Equal         .  SPEC
  1967.   -- .                                                 .
  1968.   -- ...................................................
  1969.   function Equal (P, Q: STRING) return BOOLEAN;
  1970.   --| Purpose
  1971.   --| Return True iff P = Q.
  1972.  
  1973.   -- ...................................................
  1974.   -- .                                                 .
  1975.   -- .  Case_Sensitive_String_Comparison.Less          .  SPEC
  1976.   -- .                                                 .
  1977.   -- ...................................................
  1978.   function Less (P, Q: STRING) return BOOLEAN;
  1979.   --| Purpose
  1980.   --| Return True iff P < Q.
  1981.  
  1982.   -- ...................................................
  1983.   -- .                                                 .
  1984.   -- .  Case_Sensitive_String_Comparison.Less_or_Equal .  SPEC
  1985.   -- .                                                 .
  1986.   -- ...................................................
  1987.   function Less_or_Equal (P, Q: STRING) return BOOLEAN;
  1988.   --| Purpose
  1989.   --| Return True iff P <= Q.
  1990.  
  1991.   -- ...................................................
  1992.   -- .                                                 .
  1993.   -- .  Case_Sensitive_String_Comparison.Greater       .  SPEC
  1994.   -- .                                                 .
  1995.   -- ...................................................
  1996.   function Greater (P, Q: STRING) return BOOLEAN;
  1997.   --| Purpose
  1998.   --| Return True iff P > Q.
  1999.  
  2000.   -- ......................................................
  2001.   -- .                                                    .
  2002.   -- .  Case_Sensitive_String_Comparison.Greater_or_Equal .  SPEC
  2003.   -- .                                                    .
  2004.   -- ......................................................
  2005.   function Greater_or_Equal (P, Q: STRING) return BOOLEAN;
  2006.   --| Purpose
  2007.   --| Return True iff P >= Q.
  2008.  
  2009. private
  2010.     pragma Inline (equal, less, less_or_equal, greater,
  2011.                    greater_or_equal);
  2012. end Case_Sensitive_String_Comparison;
  2013. --::::::::::
  2014. --cstrings.spc
  2015. --::::::::::
  2016. -- *********************************************************
  2017. -- *                                                       *
  2018. -- *  CStrings                                             *  SPEC
  2019. -- *                                                       *
  2020. -- *********************************************************
  2021. generic
  2022.   Max_String_Length : NATURAL := 400;  -- max length of a string
  2023.                                        -- including the trailing
  2024.                                        -- ASCII.NUL character
  2025. package CStrings is
  2026. --| Purpose
  2027. --|   CStrings provides a number of procedures and functions
  2028. --| which manipulate null-terminated strings (called C Strings)
  2029. --| and Ada strings (which contain no null character).
  2030. --| Type STRING is used to contain the C and Ada strings.
  2031. --| A C string contains a sequence of characters followed
  2032. --| by an ASCII.NUL; more characters may follow the ASCII.NUL
  2033. --| in the buffer, but they are ignored.  An Ada string is
  2034. --| a sequence of characters bound by the dimensions of the
  2035. --| buffer; all characters in the buffer are a part of the
  2036. --| string.
  2037. --|   The names of these procedures and functions were taken
  2038. --| from a listing of string-oriented C library functions.
  2039. --| The functionality of these routines is almost always
  2040. --| identical to the functionality of the original C routines.
  2041. --|
  2042. --| Initialization Exceptions (none)
  2043. --| Notes
  2044. --|   Reference Sun Release 4.0 man pages on "strings".
  2045. --|   Each string referenced in this specification is followed
  2046. --| by one of the following comments:
  2047. --|
  2048. --|    Comment      Meaning
  2049. --|    ===========  =========================================
  2050. --|    -- Ada       The string is an Ada String
  2051. --|    -- C         The string is a C String
  2052. --|    -- Ada or C  The string is an Ada String or a C String
  2053. --|
  2054. --| Modifications        Author: Richard Conn, MACA
  2055. --| 2/27/90  Richard Conn    Initial Version and Release
  2056.  
  2057.   type COMPARISON_RESULT is (LESS_THAN, EQUAL_TO, GREATER_THAN);
  2058.  
  2059.   -- Exceptions
  2060.   LENGTH_ERROR     : exception;  -- resulting string length
  2061.                                  -- is too long for buffer
  2062.  
  2063.   -- ...................................................
  2064.   -- .                                                 .
  2065.   -- .  CStrings.Make_Cstring                          .  SPEC
  2066.   -- .                                                 .
  2067.   -- ...................................................
  2068.   procedure Make_Cstring (From  : in STRING;   -- Ada or C
  2069.                           To    : out STRING); -- C
  2070.   --| Purpose
  2071.   --|   Place a copy of From into To.  Place
  2072.   --| the null terminator (ASCII.NUL) at the character
  2073.   --| in To corresponding to From(From'LAST+1).
  2074.   --|
  2075.   --| Exceptions
  2076.   --|   LENGTH_ERROR -- Destination is too short to hold
  2077.   --|                   the result or the result exceeds
  2078.   --|                   Max_String_Length characters
  2079.  
  2080.   -- ...................................................
  2081.   -- .                                                 .
  2082.   -- .  CStrings.Make_Cstring                          .  SPEC
  2083.   -- .                                                 .
  2084.   -- ...................................................
  2085.   procedure Make_Cstring (From_To : in out STRING;  -- Ada or C
  2086.                           Index   : in NATURAL);
  2087.   --| Purpose
  2088.   --|   Place a null into From_To on the indicated
  2089.   --| character.
  2090.   --|
  2091.   --| Exceptions
  2092.   --|   LENGTH_ERROR -- Index is out of bounds
  2093.  
  2094.   -- ...................................................
  2095.   -- .                                                 .
  2096.   -- .  CStrings.Ada_String                            .  SPEC
  2097.   -- .                                                 .
  2098.   -- ...................................................
  2099.   function Ada_String (From : in STRING) -- Ada or C
  2100.     return STRING;                       -- Ada
  2101.   --| Purpose
  2102.   --|   Return the slice of From up to but not including
  2103.   --| the ending NUL.  If From is an Ada string (no null),
  2104.   --| then the entire string is returned.
  2105.   --|
  2106.   --| Exceptions (none)
  2107.  
  2108.   -- ...................................................
  2109.   -- .                                                 .
  2110.   -- .  CStrings.Strcat                                .  SPEC
  2111.   -- .                                                 .
  2112.   -- ...................................................
  2113.   procedure Strcat (To   : in out STRING;   -- C
  2114.                     From : in STRING);      -- Ada or C
  2115.   function Strcat (From_Part_1 : in STRING; -- Ada or C
  2116.                    From_Part_2 : in STRING) -- Ada or C
  2117.     return STRING;                          -- C
  2118.   --| Purpose
  2119.   --|   Strcat appends a copy of string Source to the end
  2120.   --| of string Destination.  The procedure Strcat modifies
  2121.   --| the string Destination, while the function Strcat
  2122.   --| does not modify the string Destination.
  2123.   --|
  2124.   --| Exceptions
  2125.   --|   LENGTH_ERROR -- Destination is too short to hold
  2126.   --|                   the result or the result exceeds
  2127.   --|                   Max_String_Length characters
  2128.  
  2129.   -- ...................................................
  2130.   -- .                                                 .
  2131.   -- .  CStrings.Strncat                               .  SPEC
  2132.   -- .                                                 .
  2133.   -- ...................................................
  2134.   procedure Strncat (To     : in out STRING; -- C
  2135.                      From   : in STRING;     -- Ada or C
  2136.                      Length : in NATURAL);
  2137.   function Strncat  (To     : in STRING;     -- Ada or C
  2138.                      From   : in STRING;     -- Ada or C
  2139.                      Length : in NATURAL)
  2140.     return STRING;                           -- C
  2141.   --| Purpose
  2142.   --|   Strncat appends a copy of string From to the end
  2143.   --| of string To.  The procedure Strncat modifies
  2144.   --| the string To, while the function Strncat
  2145.   --| does not modify the string To.  At most Length
  2146.   --| characters are appended.
  2147.   --|
  2148.   --| Exceptions
  2149.   --|   LENGTH_ERROR -- Destination is too short to hold
  2150.   --|                   the result or the result exceeds
  2151.   --|                   Max_String_Length characters
  2152.  
  2153.   -- ...................................................
  2154.   -- .                                                 .
  2155.   -- .  CStrings.Strcmp                                .  SPEC
  2156.   -- .                                                 .
  2157.   -- ...................................................
  2158.   function Strcmp (String1 : in STRING;  -- Ada or C
  2159.                    String2 : in STRING)  -- Ada or C
  2160.     return COMPARISON_RESULT;
  2161.   --| Purpose
  2162.   --|   Strcmp compares its arguments and returns the values
  2163.   --| LESS_THAN, EQUAL_TO, or GREATER_THAN accordingly as
  2164.   --| String1 is lexicographically less than, equal to, or
  2165.   --| greater than String2.
  2166.   --|
  2167.   --| Exceptions (none)
  2168.  
  2169.   -- ...................................................
  2170.   -- .                                                 .
  2171.   -- .  CStrings.Strncmp                               .  SPEC
  2172.   -- .                                                 .
  2173.   -- ...................................................
  2174.   function Strncmp (String1 : in STRING;   -- Ada or C
  2175.                     String2 : in STRING;   -- Ada or C
  2176.                     Length  : in NATURAL)
  2177.     return COMPARISON_RESULT;
  2178.   --| Purpose
  2179.   --|   Strncmp compares its arguments and returns the values
  2180.   --| LESS_THAN, EQUAL_TO, or GREATER_THAN accordingly as
  2181.   --| String1 is lexicographically less than, equal to, or
  2182.   --| greater than String2.  Strncmp compares at most
  2183.   --| Length characters.
  2184.   --|
  2185.   --| Exceptions (none)
  2186.  
  2187.   -- ...................................................
  2188.   -- .                                                 .
  2189.   -- .  CStrings.Strcasecmp                            .  SPEC
  2190.   -- .                                                 .
  2191.   -- ...................................................
  2192.   function Strcasecmp (String1 : in STRING;  -- Ada or C
  2193.                        String2 : in STRING)  -- Ada or C
  2194.     return COMPARISON_RESULT;
  2195.   --| Purpose
  2196.   --|   Strcasecmp compares its arguments and returns the values
  2197.   --| LESS_THAN, EQUAL_TO, or GREATER_THAN accordingly as
  2198.   --| String1 is lexicographically less than, equal to, or
  2199.   --| greater than String2.  Differences in case are ignored.
  2200.   --|
  2201.   --| Exceptions (none)
  2202.  
  2203.   -- ...................................................
  2204.   -- .                                                 .
  2205.   -- .  CStrings.Strncasecmp                           .  SPEC
  2206.   -- .                                                 .
  2207.   -- ...................................................
  2208.   function Strncasecmp (String1 : in STRING;   -- Ada or C
  2209.                         String2 : in STRING;   -- Ada or C
  2210.                         Length  : in NATURAL)
  2211.     return COMPARISON_RESULT;
  2212.   --| Purpose
  2213.   --|   Strncasecmp compares its arguments and returns the values
  2214.   --| LESS_THAN, EQUAL_TO, or GREATER_THAN accordingly as
  2215.   --| String1 is lexicographically less than, equal to, or
  2216.   --| greater than String2.  Differences in case are ignored.
  2217.   --| At most Length characters are compared.
  2218.   --|
  2219.   --| Exceptions (none)
  2220.  
  2221.   -- ...................................................
  2222.   -- .                                                 .
  2223.   -- .  CStrings.Strcpy                                .  SPEC
  2224.   -- .                                                 .
  2225.   -- ...................................................
  2226.   procedure Strcpy (From : in STRING;    -- Ada or C
  2227.                     To   : out STRING);  -- C
  2228.   --| Purpose
  2229.   --|   Strcpy copies From to To, stopping after
  2230.   --| the null character has been copied.
  2231.   --|
  2232.   --| Exceptions
  2233.   --|   LENGTH_ERROR -- Destination is too short to hold
  2234.   --|                   the result
  2235.  
  2236.   -- ...................................................
  2237.   -- .                                                 .
  2238.   -- .  CStrings.Strncpy                               .  SPEC
  2239.   -- .                                                 .
  2240.   -- ...................................................
  2241.   procedure Strncpy (From   : in STRING;    -- Ada or C
  2242.                      To     : out STRING;   -- C
  2243.                      Length : in NATURAL);
  2244.   --| Purpose
  2245.   --|   Strncpy copies From to To, copying
  2246.   --| at most Length characters.  If there are more
  2247.   --| than Length characters in To, Length
  2248.   --| characters will be copied and a trailing null
  2249.   --| appended after the last character.
  2250.   --|
  2251.   --| Exceptions
  2252.   --|   LENGTH_ERROR -- Destination is too short to hold
  2253.   --|                   the result
  2254.  
  2255.   -- ...................................................
  2256.   -- .                                                 .
  2257.   -- .  CStrings.Strlen                                .  SPEC
  2258.   -- .                                                 .
  2259.   -- ...................................................
  2260.   function Strlen (String1 : in STRING)  -- Ada or C
  2261.     return NATURAL;
  2262.   pragma inline (Strlen);
  2263.   --| Purpose
  2264.   --|   Strlen returns the number of characters in String1,
  2265.   --| not including the null-terminating character.
  2266.   --|
  2267.   --| Exceptions (none)
  2268.  
  2269.   -- ...................................................
  2270.   -- .                                                 .
  2271.   -- .  CStrings.Strchr                                .  SPEC
  2272.   -- .                                                 .
  2273.   -- ...................................................
  2274.   function Strchr (String1 : in STRING;     -- Ada or C
  2275.                    Char1   : in CHARACTER)
  2276.     return NATURAL;
  2277.   --| Purpose
  2278.   --|   Strchr returns the index of the first occurrence
  2279.   --| of Char1 in the string String1 or the value 0 if
  2280.   --| Char1 does not occur in String1.  The null-terminating
  2281.   --| character is considered to be part of String1.
  2282.   --|
  2283.   --| Exceptions (none)
  2284.   --|
  2285.   --| Notes
  2286.   --|   This function is identical to the index and strchr
  2287.   --| functions in C.
  2288.  
  2289.   -- ...................................................
  2290.   -- .                                                 .
  2291.   -- .  CStrings.Strrchr                               .  SPEC
  2292.   -- .                                                 .
  2293.   -- ...................................................
  2294.   function Strrchr (String1 : in STRING;    -- Ada or C
  2295.                     Char1   : in CHARACTER)
  2296.     return NATURAL;
  2297.   --| Purpose
  2298.   --|   Strrchr returns the index of the last occurrence
  2299.   --| of Char1 in the string String1 or the value 0 if
  2300.   --| Char1 does not occur in String1.  The null-terminating
  2301.   --| character is considered to be part of String1.
  2302.   --|
  2303.   --| Exceptions (none)
  2304.   --|
  2305.   --| Notes
  2306.   --|   This function is identical to the rindex and strrchr
  2307.   --| functions in C.
  2308.  
  2309.   -- ...................................................
  2310.   -- .                                                 .
  2311.   -- .  CStrings.Strpbrk                               .  SPEC
  2312.   -- .                                                 .
  2313.   -- ...................................................
  2314.   function Strpbrk (String1 : in STRING;  -- Ada or C
  2315.                     String2 : in STRING)  -- Ada or C
  2316.     return NATURAL;
  2317.   --| Purpose
  2318.   --|   Strpbrk returns the index of the first occurrence in
  2319.   --| String1 of any character from String2 or the value 0 if
  2320.   --| no character from String2 exists in String1.
  2321.   --|
  2322.   --| Exceptions (none)
  2323.  
  2324.   -- ...................................................
  2325.   -- .                                                 .
  2326.   -- .  CStrings.Strspn                                .  SPEC
  2327.   -- .                                                 .
  2328.   -- ...................................................
  2329.   function Strspn (String1 : in STRING;  -- Ada or C
  2330.                    String2 : in STRING)  -- Ada or C
  2331.     return NATURAL;
  2332.   --| Purpose
  2333.   --|   Strspn returns the length of the initial segment
  2334.   --| of String1 which consists entirely of characters
  2335.   --| from String2.
  2336.   --|
  2337.   --| Exceptions (none)
  2338.  
  2339.   -- ...................................................
  2340.   -- .                                                 .
  2341.   -- .  CStrings.Strcspn                               .  SPEC
  2342.   -- .                                                 .
  2343.   -- ...................................................
  2344.   function Strcspn (String1 : in STRING;  -- Ada or C
  2345.                     String2 : in STRING)  -- Ada or C
  2346.     return NATURAL;
  2347.   --| Purpose
  2348.   --|   Strcspn returns the length of the initial segment
  2349.   --| of String1 which consists entirely of characters
  2350.   --| not from String2.
  2351.   --|
  2352.   --| Exceptions (none)
  2353.  
  2354.   -- ...................................................
  2355.   -- .                                                 .
  2356.   -- .  CStrings.Strtok                                .  SPEC
  2357.   -- .                                                 .
  2358.   -- ...................................................
  2359.   procedure Strtok (Target     : in STRING;      -- Ada or C
  2360.                     Start      : in out NATURAL;
  2361.                     Delimiters : in STRING;      -- Ada or C
  2362.                     Next_Token : out STRING);    -- C
  2363.   --| Purpose
  2364.   --|   Strtok considers the string Target to consist of a
  2365.   --| sequence of zero or more text tokens separated by spans
  2366.   --| of one or more characters from the separator string
  2367.   --| Delimiters.  A call to Strtok returns the first token
  2368.   --| in Target on or after the character indexed by Start.
  2369.   --| This token is returned in the string Next_Token with
  2370.   --| a null character immediately following the token.
  2371.   --| The separator string Delimiters may be different from
  2372.   --| call to call.
  2373.   --|
  2374.   --| Strtok must be called with Start's actual parameter
  2375.   --| being an initialized variable; generally, Start's
  2376.   --| initial value is Target'FIRST.
  2377.   --|
  2378.   --| Exceptions
  2379.   --|   LENGTH_ERROR -- Next_Token is too short to hold
  2380.   --|                   the result
  2381.  
  2382. end CStrings;
  2383. --::::::::::
  2384. --darray.spc
  2385. --::::::::::
  2386. -- **************************************************
  2387. -- *                                                *
  2388. -- *  DARRAY_PKG                                    *  SPEC
  2389. -- *                                                *
  2390. -- **************************************************
  2391. generic
  2392.     type ELEM_TYPE is private;
  2393.     with function Equal (E1, E2: ELEM_TYPE)
  2394.         return BOOLEAN is "=";
  2395. package Darray_Pkg is
  2396. --| Purpose
  2397. --| This package provides the dynamic array (darray) abstract data type.
  2398. --| A darray has completely dynamic bounds, which change during runtime as
  2399. --| elements are added to/removed from the top/bottom. darrays are similar
  2400. --| to deques, differing only in that operations for indexing into the
  2401. --| structure are also provided.  A darray is indexed by integers that
  2402. --| fall within the current bounds.  The component type, elem_type, of a
  2403. --| darray is a generic formal parameter of this package, along with a
  2404. --| function, equal, that is assumed to form an equality relation over
  2405. --| over elem_type.
  2406. --|
  2407. --| The notation, <first, elts>, will be used to denote a darray.
  2408. --| first is the current low bound of the darray.  elts is the sequence
  2409. --| of elements contained in the darray.  For a given darray, d, the
  2410. --| dot selection mechanism is used to refer to these components, e.g.,
  2411. --| d.first and d.elts.  & is used for sequence concatenation, and also
  2412. --| for prepending/postpending a single element to a sequence.  |s| is
  2413. --| the number of elements in a sequence, s, and () is the null sequence.
  2414. --| Standard Ada array indexing notation is adopted for sequences.
  2415. --|
  2416. --| Initialization Exceptions (none)
  2417. --| Notes (none)
  2418. --|
  2419. --| Modifications
  2420. --| Programmer: Ron Kownacki, Intermetrics
  2421.  
  2422. -- Primary Types
  2423.   type DARRAY is private;
  2424.   type ARRAY_TYPE is array (INTEGER range <>) of ELEM_TYPE;
  2425.  
  2426. -- Storage Management Constants and Types  (see create procedure)
  2427.   Default_Predict : constant POSITIVE := 100;
  2428.   Default_High    : constant POSITIVE := 50;
  2429.   Default_Expand  : constant POSITIVE := 100;
  2430.  
  2431. -- Exceptions
  2432.   No_More       : exception;  -- Raised on incorrect use of an iterator.
  2433.   Out_of_Bounds : exception;  -- Raised on index out of current bounds.
  2434.   Uninitialized_Darray : exception;
  2435.         -- Raised on use of uninitialized darray by most operations.
  2436.  
  2437. -- Iterators
  2438.   type ELEMENTS_ITER is private;
  2439.  
  2440. -- Constructors
  2441.  
  2442.   -- ...................................................
  2443.   -- .                                                 .
  2444.   -- .  DARRAY_PKG.CREATE                              .  SPEC
  2445.   -- .                                                 .
  2446.   -- ...................................................
  2447.   procedure Create(First:          in     INTEGER := 1;
  2448.                    Predict:        in     POSITIVE := Default_Predict;
  2449.                    High_Percent:   in     POSITIVE := Default_High;
  2450.                    Expand_Percent: in     POSITIVE := Default_Expand;
  2451.                    D:              in out DARRAY);
  2452.   --| Purpose
  2453.   --| Sets d to <first, ()>.  If d has previously been initialized,
  2454.   --| then a destroy(d) is first performed.  The predict parameter
  2455.   --| specifies the initial space allocated.  (predict  = #elements).
  2456.   --| The high_percent parameter is the caller's expectation of the
  2457.   --| percentage of add_highs, out of total adds, to the darray.  For
  2458.   --| example, a caller would specify 100 if it was known that no
  2459.   --| add_lows would be performed.  The expand_percent parameter
  2460.   --| specifies the amount of additional space, as a percentage of
  2461.   --| currently allocated space, that is to be allocated whenever an
  2462.   --| expansion becomes necessary.  For example, 100 doubles the
  2463.   --| allocated space.
  2464.   --|
  2465.   --| Exceptions (none)
  2466.   --| Notes (none)
  2467.   
  2468.   -- ...................................................
  2469.   -- .                                                 .
  2470.   -- .  DARRAY_PKG.ARRAY_TO_DARRAY                     .  SPEC
  2471.   -- .                                                 .
  2472.   -- ...................................................
  2473.   procedure Array_to_Darray(A:              in     ARRAY_TYPE;
  2474.                             First:          in     INTEGER := 1;
  2475.                             Predict:        in     POSITIVE;
  2476.                             High_Percent:   in     POSITIVE
  2477.                                                      := Default_High;
  2478.                             Expand_Percent: in     POSITIVE
  2479.                                                      := Default_Expand;
  2480.                             D:              in out DARRAY);
  2481.   --| Purpose
  2482.   --| Sets d to <first, a(a'first..a'last)>.  If d has previously
  2483.   --| been initialized, then an implicit destroy(d) is performed.
  2484.   --| The high_percent and expand_percent parameters are defined
  2485.   --| as for create.  Raises out_of_bounds iff predict < a'length.
  2486.   --|
  2487.   --| Exceptions
  2488.   --|   out_of_bounds
  2489.   --|
  2490.   --| Notes (none)
  2491.  
  2492.   -- ...................................................
  2493.   -- .                                                 .
  2494.   -- .  DARRAY_PKG.SET_FIRST                           .  SPEC
  2495.   -- .                                                 .
  2496.   -- ...................................................
  2497.   procedure Set_First(D:     in out DARRAY;
  2498.                       First: in     INTEGER);
  2499.   --| Purpose
  2500.   --| Sets d.first to first.
  2501.   --| Raises uninitialized_darray if d has not been initialized.
  2502.   --|
  2503.   --| Exceptions
  2504.   --|   uninitialized_darray
  2505.   --|
  2506.   --| Notes (none)
  2507.  
  2508.   -- ...................................................
  2509.   -- .                                                 .
  2510.   -- .  DARRAY_PKG.ADD_LOW                             .  SPEC
  2511.   -- .                                                 .
  2512.   -- ...................................................
  2513.   procedure Add_Low (D: in out DARRAY;
  2514.                      E: in     ELEM_TYPE);
  2515.   --| Purpose
  2516.   --| Sets d to <d.first - 1, e & d.elts>.
  2517.   --| Raises uninitialized_darray if d has not been initialized.
  2518.   --|
  2519.   --| Exceptions
  2520.   --|   uninitialized_darray
  2521.   --|
  2522.   --| Notes (none)
  2523.  
  2524.   -- ...................................................
  2525.   -- .                                                 .
  2526.   -- .  DARRAY_PKG.ADD_HIGH                            .  SPEC
  2527.   -- .                                                 .
  2528.   -- ...................................................
  2529.   procedure Add_High (D: in out DARRAY;
  2530.                       E: in     ELEM_TYPE);
  2531.   --| Purpose
  2532.   --| Sets d.elts to d.elts & e.
  2533.   --| Raises uninitialized_darray if d has not been initialized.
  2534.   --|
  2535.   --| Exceptions
  2536.   --|   uninitialized_darray
  2537.   --|
  2538.   --| Notes (none)
  2539.  
  2540.   -- ...................................................
  2541.   -- .                                                 .
  2542.   -- .  DARRAY_PKG.REMOVE_LOW                          .  SPEC
  2543.   -- .                                                 .
  2544.   -- ...................................................
  2545.   procedure Remove_Low (D: in out DARRAY);
  2546.   --| Purpose
  2547.   --| Sets d to <d.first + 1, d.elts(d.first + 1 .. last(d))>.
  2548.   --| Raises out_of_bounds iff is_empty(d).
  2549.   --| Raises uninitialized_darray if d has not been initialized.
  2550.   --|
  2551.   --| Exceptions
  2552.   --|   uninitialized_darray
  2553.   --|   out_of_bounds
  2554.   --|
  2555.   --| Notes (none)
  2556.  
  2557.   -- ...................................................
  2558.   -- .                                                 .
  2559.   -- .  DARRAY_PKG.REMOVE_HIGH                         .  SPEC
  2560.   -- .                                                 .
  2561.   -- ...................................................
  2562.   procedure Remove_High (D: in out DARRAY);
  2563.   --| Purpose
  2564.   --| Sets d.elts to d.elts(d.first..last(d) - 1).
  2565.   --| Raises out_of_bounds iff is_empty(d).
  2566.   --| Raises uninitialized_darray if d has not been initialized.
  2567.   --|
  2568.   --| Exceptions
  2569.   --|   uninitialized_darray
  2570.   --|   out_of_bounds
  2571.   --|
  2572.   --| Notes (none)
  2573.  
  2574.   -- ...................................................
  2575.   -- .                                                 .
  2576.   -- .  DARRAY_PKG.STORE                               .  SPEC
  2577.   -- .                                                 .
  2578.   -- ...................................................
  2579.   procedure Store (D: in out DARRAY;
  2580.                    I: in     INTEGER;
  2581.                    E: in     ELEM_TYPE);
  2582.   --| Purpose
  2583.   --| Replaces d.elts(i) with e.  Raises out_of_bounds iff
  2584.   --| either is_empty(d) or i is not in d.first..last(d).
  2585.   --| Raises uninitialized_darray if d has not been initialized.
  2586.   --|
  2587.   --| Exceptions
  2588.   --|   uninitialized_darray
  2589.   --|   out_of_bounds
  2590.   --|
  2591.   --| Notes (none)
  2592.  
  2593.   -- ...................................................
  2594.   -- .                                                 .
  2595.   -- .  DARRAY_PKG.COPY                                .  SPEC
  2596.   -- .                                                 .
  2597.   -- ...................................................
  2598.   function Copy (D: DARRAY) return DARRAY;
  2599.   --| Purpose
  2600.   --| Returns a copy of d.  Subsequent changes to the structure of d
  2601.   --| will not be visible through the application of operations to
  2602.   --| the copy of d, and vice versa.  Assignment or parameter passing
  2603.   --| without using copy (or copy_deep, described below) will result
  2604.   --| in a single darray value being shared among objects.
  2605.   --| Raises uninitialized_darray if d has not been initialized.
  2606.   --| The assignment operation is used to transfer the values of
  2607.   --| the elem_type component objects of d; consequently, changes
  2608.   --| in these values may be observable through both darrays if
  2609.   --| elem_type is an access type, or contains access type
  2610.   --| components.
  2611.   --|
  2612.   --| Exceptions
  2613.   --|   uninitialized_darray
  2614.   --|
  2615.   --| Notes (none)
  2616.       
  2617.   -- ...................................................
  2618.   -- .                                                 .
  2619.   -- .  DARRAY_PKG.COPY_DEEP                           .  SPEC
  2620.   -- .                                                 .
  2621.   -- ...................................................
  2622.   generic
  2623.     with function Copy (E: ELEM_TYPE) return ELEM_TYPE;
  2624.   function Copy_Deep (D: DARRAY) return DARRAY;
  2625.   --| Purpose
  2626.   --| Returns a copy of d.  Subsequent changes to the structure of d
  2627.   --| will not be visible through the application of operations to
  2628.   --| the copy of d, and vice versa.  Assignment or parameter passing
  2629.   --| without using copy_deep or copy will result in a single
  2630.   --| darray value being shared among objects.
  2631.   --| Raises uninitialized_darray if d has not been initialized.
  2632.   --| The transfer of elem_type component objects is accomplished by
  2633.   --| using the assignment operation in conjunction with the copy
  2634.   --| function.  Consequently, the user can prevent sharing of
  2635.   --| elem_type access components.
  2636.   --|
  2637.   --| Exceptions
  2638.   --|   uninitialized_darray
  2639.   --|
  2640.   --| Notes (none)
  2641.     
  2642. -- Query Operations
  2643.  
  2644.   -- ...................................................
  2645.   -- .                                                 .
  2646.   -- .  DARRAY_PKG.FETCH                               .  SPEC
  2647.   -- .                                                 .
  2648.   -- ...................................................
  2649.   function Fetch (D: DARRAY; I: INTEGER) return ELEM_TYPE;
  2650.   --| Purpose
  2651.   --| Returns d.elts(i).  Raises out_of_bounds iff either is_empty(d)
  2652.   --| or i is not in d.first..last(d).
  2653.   --| Raises uninitialized_darray if d has not been initialized.
  2654.   --|
  2655.   --| Exceptions
  2656.   --|   out_of_bounds
  2657.   --|   uninitialized_darray
  2658.   --|
  2659.   --| Notes (none)
  2660.  
  2661.   -- ...................................................
  2662.   -- .                                                 .
  2663.   -- .  DARRAY_PKG.LOW                                 .  SPEC
  2664.   -- .                                                 .
  2665.   -- ...................................................
  2666.   function Low (D: in DARRAY) return ELEM_TYPE;
  2667.   --| Purpose
  2668.   --| Returns d.elts(d.first).  Raises out_of_bounds iff is_empty(d).
  2669.   --| Raises uninitialized_darray if d has not been initialized.
  2670.   --|
  2671.   --| Exceptions
  2672.   --|   out_of_bounds
  2673.   --|   uninitialized_darray
  2674.   --|
  2675.   --| Notes (none)
  2676.  
  2677.   -- ...................................................
  2678.   -- .                                                 .
  2679.   -- .  DARRAY_PKG.HIGH                                .  SPEC
  2680.   -- .                                                 .
  2681.   -- ...................................................
  2682.   function High (D: in DARRAY) return ELEM_TYPE;
  2683.   --| Purpose
  2684.   --| Returns d.elts(last(d)).  Raises out_of_bounds iff is_empty(d).
  2685.   --| Raises uninitialized_darray if d has not been initialized.
  2686.   --|
  2687.   --| Exceptions
  2688.   --|   out_of_bounds
  2689.   --|   uninitialized_darray
  2690.   --|
  2691.   --| Notes (none)
  2692.  
  2693.   -- ...................................................
  2694.   -- .                                                 .
  2695.   -- .  DARRAY_PKG.FIRST                               .  SPEC
  2696.   -- .                                                 .
  2697.   -- ...................................................
  2698.   function First (D: in DARRAY) return INTEGER;
  2699.   --| Purpose
  2700.   --| Returns d.first.
  2701.   --| Raises uninitialized_darray if d has not been initialized.
  2702.   --|
  2703.   --| Exceptions
  2704.   --|   uninitialized_darray
  2705.   --|
  2706.   --| Notes (none)
  2707.  
  2708.   -- ...................................................
  2709.   -- .                                                 .
  2710.   -- .  DARRAY_PKG.LAST                                .  SPEC
  2711.   -- .                                                 .
  2712.   -- ...................................................
  2713.   function Last (D: in DARRAY) return INTEGER;
  2714.   --| Purpose
  2715.   --| Returns d.first + |d.elts| - 1.
  2716.   --| Raises uninitialized_darray if d has not been initialized.
  2717.   --|
  2718.   --| Exceptions
  2719.   --|   uninitialized_darray
  2720.   --|
  2721.   --| Notes (none)
  2722.  
  2723.   -- ...................................................
  2724.   -- .                                                 .
  2725.   -- .  DARRAY_PKG.IS_EMPTY                            .  SPEC
  2726.   -- .                                                 .
  2727.   -- ...................................................
  2728.   function Is_Empty (D: in DARRAY) return BOOLEAN;
  2729.   --| Purpose
  2730.   --| Returns length(d) = 0, or equivalently, last(d) < d.first.
  2731.   --| Raises uninitialized_darray if d has not been initialized.
  2732.   --|
  2733.   --| Exceptions
  2734.   --|   uninitialized_darray
  2735.   --|
  2736.   --| Notes (none)
  2737.  
  2738.   -- ...................................................
  2739.   -- .                                                 .
  2740.   -- .  DARRAY_PKG.LENGTH                              .  SPEC
  2741.   -- .                                                 .
  2742.   -- ...................................................
  2743.   function Length (D: in DARRAY) return NATURAL;
  2744.   --| Purpose
  2745.   --| Returns |d.elts|.
  2746.   --| Raises uninitialized_darray if d has not been initialized.
  2747.   --|
  2748.   --| Exceptions
  2749.   --|   uninitialized_darray
  2750.   --|
  2751.   --| Notes (none)
  2752.  
  2753.   -- ...................................................
  2754.   -- .                                                 .
  2755.   -- .  DARRAY_PKG.EQUAL                               .  SPEC
  2756.   -- .                                                 .
  2757.   -- ...................................................
  2758.   function Equal (D1, D2: DARRAY) return BOOLEAN;
  2759.   --| Purpose
  2760.   --| Return (d1.first = d2.first and
  2761.   --|         last(d1) = last(d2) and
  2762.   --|         for each i in d1.first..last(d1),
  2763.   --|             equal(d1.elts(i), d2.elts(i)).
  2764.   --| Raises uninitialized_darray if either d1 or d2 has not been
  2765.   --| initialized.  Note that (d1 = d2) implies that equal(d1, d2)
  2766.   --| will always hold.  "=" is object equality, equal is state
  2767.   --| equality.
  2768.   --|
  2769.   --| Exceptions
  2770.   --|   uninitialized_darray
  2771.   --|
  2772.   --| Notes (none)
  2773.  
  2774.   -- ...................................................
  2775.   -- .                                                 .
  2776.   -- .  DARRAY_PKG.DARRAY_TO_DARRAY                    .  SPEC
  2777.   -- .                                                 .
  2778.   -- ...................................................
  2779.   function Darray_to_Array (D: DARRAY) return ARRAY_TYPE;
  2780.   --| Purpose
  2781.   --| Let bounds_range be d.first..d.first + length(d) - 1.  If
  2782.   --| bounds_range is empty, then return an empty array with bounds
  2783.   --| of 1..0.  Otherwise, return bounds_range'(d.elts).
  2784.   --| Raises uninitialized_darray if d has not been initialized.
  2785.   --|
  2786.   --| Exceptions
  2787.   --|   uninitialized_darray
  2788.   --|
  2789.   --| Notes (none)
  2790.  
  2791. -- Iterators
  2792.  
  2793.   -- ...................................................
  2794.   -- .                                                 .
  2795.   -- .  DARRAY_PKG.MAKE_ELEMENTS_ITER                  .  SPEC
  2796.   -- .                                                 .
  2797.   -- ...................................................
  2798.   function Make_Elements_Iter (D: DARRAY) return ELEMENTS_ITER;
  2799.   --| Purpose
  2800.   --| Create and return an elements itererator based on d.  This
  2801.   --| object can then be used in conjunction with the more function
  2802.   --| and the next procedure to iterate over the components of d.
  2803.   --| Raises uninitialized_darray if d has not been initialized.
  2804.   --|
  2805.   --| Exceptions
  2806.   --|   uninitialized_darray
  2807.   --|
  2808.   --| Notes (none)
  2809.  
  2810.   -- ...................................................
  2811.   -- .                                                 .
  2812.   -- .  DARRAY_PKG.MORE                                .  SPEC
  2813.   -- .                                                 .
  2814.   -- ...................................................
  2815.   function More (Iter: ELEMENTS_ITER) return BOOLEAN;
  2816.   --| Purpose
  2817.   --| Return true iff the elements iterator has not been exhausted.
  2818.   --|
  2819.   --| Exceptions (none)
  2820.   --| Notes (none)
  2821.  
  2822.   -- ...................................................
  2823.   -- .                                                 .
  2824.   -- .  DARRAY_PKG.NEXT                                .  SPEC
  2825.   -- .                                                 .
  2826.   -- ...................................................
  2827.   procedure Next (Iter: in out ELEMENTS_ITER;
  2828.                   E:       out ELEM_TYPE);
  2829.   --| Purpose
  2830.   --| Let iter be based on the darray, d.  Successive calls of next
  2831.   --| will return, in e, successive elements of d.elts.  Each call
  2832.   --| updates the state of the elements iterator.  After all elements
  2833.   --| have been returned, an invocation of next will raise no_more.
  2834.   --| Requires:
  2835.   --| d must not be changed between the invocations of
  2836.   --| make_elements_iterator(d) and next.
  2837.   --|
  2838.   --| Exceptions
  2839.   --|   no_more
  2840.   --|
  2841.   --| Notes (none)
  2842.  
  2843. -- Heap Management
  2844.  
  2845.   -- ...................................................
  2846.   -- .                                                 .
  2847.   -- .  DARRAY_PKG.DESTROY                             .  SPEC
  2848.   -- .                                                 .
  2849.   -- ...................................................
  2850.   procedure Destroy (D: in out DARRAY);
  2851.   --| Purpose
  2852.   --| Return space consumed by the darray value associated with object
  2853.   --| d to the heap.  (If d is uninitialized, this operation does
  2854.   --| nothing.)  If other objects share the same darray value, then
  2855.   --| further use of these objects is erroneous.  Components of type
  2856.   --| elem_type, if they are access types, are not garbage collected.
  2857.   --| It is the user's responsibility to dispose of these objects.
  2858.   --| d is left in the uninitialized state.
  2859.   --|
  2860.   --| Exceptions (none)
  2861.   --| Notes (none)
  2862.  
  2863. private
  2864.     type ARRAY_PTR is access ARRAY_TYPE;
  2865.     type DARRAY_INFO is
  2866.         record
  2867.             First_Idx      : POSITIVE;
  2868.             Last_Idx       : NATURAL;
  2869.             First          : INTEGER;
  2870.             High_Percent   : POSITIVE;
  2871.             Expand_Percent : POSITIVE;
  2872.             Arr            : ARRAY_PTR := null;
  2873.         end record;
  2874.     type DARRAY is access DARRAY_INFO;
  2875.  
  2876.     -- Let r be an instance of the representation type.
  2877.     -- Representation Invariants:
  2878.     -- 1. r /= null, r.arr /= null (must be initialized to be valid.)
  2879.     -- 2. r.arr'first = 1 and
  2880.     --    r.arr'last >= 1
  2881.     -- 3. r.first_idx <= r.last_idx or
  2882.     --    r.first_idx = r.last_idx + 1
  2883.     -- 4. r.first_idx <= r.last_idx =>
  2884.     --        r.first_idx, r.last_idx in r.arr'range
  2885.     -- 5. r.expand_percent, r.high_percent get values at creation time,
  2886.     --    and these never change.
  2887.     --
  2888.     -- Abstraction Function:  (denoted by A(r))
  2889.     -- if r.last_idx < r.first_idx then
  2890.     --     <r.first, ()>
  2891.     -- else
  2892.     --     <r.first, (r.arr(r.first_idx),...,r.arr(r.last_idx))>
  2893.     --
  2894.     -- These properties follow:
  2895.     -- 1. length(A(r)) = r.last_idx - r.first_idx + 1
  2896.     -- 2. last(A(r)) = r.first + r.last_idx - r.first_idx
  2897.     -- 3. fetch(A(r), i) =
  2898.     --        if (i - r.first + r.first_idx) in r.first_idx..r.last_idx
  2899.     --            then r.arr(i - r.first + r.first_idx)
  2900.     --            else undefined.  (out_of_bounds)
  2901.  
  2902.     type ELEMENTS_ITER is
  2903.         record
  2904.             Last    : INTEGER := 0;
  2905.             Current : INTEGER := 1;
  2906.             Arr     : ARRAY_PTR;
  2907.         end record;
  2908.  
  2909.       -- Let d be the darray that an elements_iter, i, is based on.
  2910.       -- Initially, i.current = d.first_idx, i.last = d.last_idx, and
  2911.       -- i.arr = d.arr.
  2912.       -- more(i) = i.current <= i.last.
  2913.       -- next(i) = i.arr(current).  i.current incremented by next.
  2914.       -- Note that if an elements_iter object is not initialized, then
  2915.       -- more is false.
  2916.  
  2917. end Darray_Pkg;
  2918. --::::::::::
  2919. --dlist.spc
  2920. --::::::::::
  2921. -- *****************************************************************
  2922. -- *                                                               *
  2923. -- *  DOUBLY_LINKED_LIST                                           *  SPEC
  2924. -- *                                                               *
  2925. -- *****************************************************************
  2926. generic
  2927.    type ELEMENT_OBJECT is private;
  2928. package Doubly_Linked_List is
  2929. --| Purpose   
  2930. --| DOUBLY_LINKED_LIST manipulates the abstract data type
  2931. --| LIST_ID, which is a linked list of objects.
  2932. --| DOUBLE_LIST provides routines to add objects to,
  2933. --| delete objects from, and extract objects from
  2934. --| the list.  DOUBLE_LIST also allows the user to
  2935. --| move about through the list and manipulate the
  2936. --| list in various ways.
  2937. --|
  2938. --| Initialization Exceptions (none)
  2939. --|
  2940. --| Notes
  2941. --| The number of list elements is restricted to 
  2942. --| INTEGER'LAST and the amount of memory or virtual
  2943. --| memory in the computer system.
  2944. --|
  2945. --| Modifications
  2946. --| Author: Richard Conn
  2947.    
  2948. -- Types
  2949.   type ELEMENT_POSITION is new INTEGER range 0 .. INTEGER'LAST;
  2950.   type LIST_ID is limited private;
  2951.    
  2952. -- Exceptions
  2953.   ADVANCE_PAST_END_OF_LIST          : exception;
  2954.   BACKUP_BEFORE_BEGINNING_OF_LIST   : exception;
  2955.   DYNAMIC_MEMORY_ALLOCATION_PROBLEM : exception;
  2956.   LIST_IS_EMPTY                     : exception;
  2957.   INVALID_INDEX                     : exception;
  2958.   UNEXPECTED_ERROR                  : exception;  -- raised anytime
  2959.    
  2960.   -- .............................................................
  2961.   -- .                                                           .
  2962.   -- .  DOUBLY_LINKED_LIST.INITIALIZE                            .  SPEC
  2963.   -- .                                                           .
  2964.   -- .............................................................
  2965.   procedure Initialize (ID : in out LIST_ID);
  2966.   --| Purpose
  2967.   --| Initialize the list to empty (the list is empty when
  2968.   --| first used); if the list contained any elements, they
  2969.   --| are deleted.
  2970.   --|
  2971.   --| Exceptions (none)
  2972.   --| Notes (none)
  2973.    
  2974.   -- .............................................................
  2975.   -- .                                                           .
  2976.   -- .  DOUBLY_LINKED_LIST.FIRST_ELEMENT                         .  SPEC
  2977.   -- .                                                           .
  2978.   -- .............................................................
  2979.   function First_Element (ID : in LIST_ID) return ELEMENT_OBJECT;
  2980.   --| Purpose
  2981.   --| Return the first element of the list.
  2982.   --|
  2983.   --| Exceptions
  2984.   --|   LIST_IS_EMPTY
  2985.   --|
  2986.   --| Notes (none)
  2987.  
  2988.   -- .............................................................
  2989.   -- .                                                           .
  2990.   -- .  DOUBLY_LINKED_LIST.LAST_ELEMENT                          .  SPEC
  2991.   -- .                                                           .
  2992.   -- .............................................................
  2993.   function Last_Element (ID : in LIST_ID) return ELEMENT_OBJECT;
  2994.   --| Purpose
  2995.   --| Return the last element of the list.
  2996.   --|
  2997.   --| Exceptions
  2998.   --|   LIST_IS_EMPTY
  2999.   --|
  3000.   --| Notes (none)
  3001.    
  3002.   -- .............................................................
  3003.   -- .                                                           .
  3004.   -- .  DOUBLY_LINKED_LIST.CURRENT_ELEMENT                       .  SPEC
  3005.   -- .                                                           .
  3006.   -- .............................................................
  3007.   function Current_Element (ID : in LIST_ID) return ELEMENT_OBJECT;
  3008.   --| Purpose
  3009.   --| Return the current element of the list.
  3010.   --|
  3011.   --| Exceptions
  3012.   --|   LIST_IS_EMPTY
  3013.   --|
  3014.   --| Notes (none)
  3015.    
  3016.   -- .............................................................
  3017.   -- .                                                           .
  3018.   -- .  DOUBLY_LINKED_LIST.GOTO_FIRST                            .  SPEC
  3019.   -- .                                                           .
  3020.   -- .............................................................
  3021.   procedure Goto_First (ID : in out LIST_ID);
  3022.   --| Purpose
  3023.   --| Set the current element of the list to be the first
  3024.   --| element.
  3025.   --|
  3026.   --| Exceptions
  3027.   --|   LIST_IS_EMPTY
  3028.   --|
  3029.   --| Notes (none)
  3030.    
  3031.   -- .............................................................
  3032.   -- .                                                           .
  3033.   -- .  DOUBLY_LINKED_LIST.GOTO_LAST                             .  SPEC
  3034.   -- .                                                           .
  3035.   -- .............................................................
  3036.   procedure Goto_Last (ID : in out LIST_ID);
  3037.   --| Purpose
  3038.   --| Set the current element of the list to be the last
  3039.   --| element.
  3040.   --|
  3041.   --| Exceptions
  3042.   --|   LIST_IS_EMPTY
  3043.   --|
  3044.   --| Notes (none)
  3045.    
  3046.   -- .............................................................
  3047.   -- .                                                           .
  3048.   -- .  DOUBLY_LINKED_LIST.GOTO_ELEMENT                          .  SPEC
  3049.   -- .                                                           .
  3050.   -- .............................................................
  3051.   procedure Goto_Element (ID    : in out LIST_ID;
  3052.                           Index : in ELEMENT_POSITION);
  3053.   --| Purpose
  3054.   --| Set the current element of the list to be the Nth (INDEX)
  3055.   --| element.
  3056.   --|
  3057.   --| Exceptions
  3058.   --|   INVALID_INDEX
  3059.   --|   LIST_IS_EMPTY
  3060.   --|
  3061.   --| Notes (none)
  3062.    
  3063.   -- .............................................................
  3064.   -- .                                                           .
  3065.   -- .  DOUBLY_LINKED_LIST.CURRENT_INDEX                         .  SPEC
  3066.   -- .                                                           .
  3067.   -- .............................................................
  3068.   function Current_Index (ID : in LIST_ID) return ELEMENT_POSITION;
  3069.   --| Purpose
  3070.   --| Return the number of the current element.
  3071.   --|
  3072.   --| Exceptions
  3073.   --|   LIST_IS_EMPTY
  3074.   --|
  3075.   --| Notes (none)
  3076.    
  3077.   -- .............................................................
  3078.   -- .                                                           .
  3079.   -- .  DOUBLY_LINKED_LIST.LAST_INDEX                            .  SPEC
  3080.   -- .                                                           .
  3081.   -- .............................................................
  3082.   function Last_Index (ID : in LIST_ID) return ELEMENT_POSITION;
  3083.   --| Purpose
  3084.   --| Return the number of the last element.
  3085.   --|
  3086.   --| Exceptions
  3087.   --|   LIST_IS_EMPTY
  3088.   --|
  3089.   --| Notes (none)
  3090.    
  3091.   -- .............................................................
  3092.   -- .                                                           .
  3093.   -- .  DOUBLY_LINKED_LIST.ADVANCE                               .  SPEC
  3094.   -- .                                                           .
  3095.   -- .............................................................
  3096.   procedure Advance (ID : in out LIST_ID);
  3097.   --| Purpose
  3098.   --| Advance, setting the current element to be the next
  3099.   --| element.
  3100.   --|
  3101.   --| Exceptions
  3102.   --|   ADVANCE_PAST_END_OF_LIST
  3103.   --|   LIST_IS_EMPTY
  3104.   --|
  3105.   --| Notes (none)
  3106.    
  3107.   -- .............................................................
  3108.   -- .                                                           .
  3109.   -- .  DOUBLY_LINKED_LIST.BACKUP                                .  SPEC
  3110.   -- .                                                           .
  3111.   -- .............................................................
  3112.   procedure Backup (ID : in out LIST_ID);
  3113.   --| Purpose
  3114.   --| Backup, setting the current element to be the previous
  3115.   --| element.
  3116.   --|
  3117.   --| Exceptions
  3118.   --|   BACKUP_BEFORE_BEGINNING_OF_LIST
  3119.   --|   LIST_IS_EMPTY
  3120.   --|
  3121.   --| Notes (none)
  3122.    
  3123.   -- .............................................................
  3124.   -- .                                                           .
  3125.   -- .  DOUBLY_LINKED_LIST.IS_EMPTY                              .  SPEC
  3126.   -- .                                                           .
  3127.   -- .............................................................
  3128.   function Is_Empty (ID : in LIST_ID) return BOOLEAN;
  3129.   --| Purpose
  3130.   --| Return TRUE if the list is empty.
  3131.   --|
  3132.   --| Exceptions (none)
  3133.   --| Notes (none)
  3134.    
  3135.   -- .............................................................
  3136.   -- .                                                           .
  3137.   -- .  DOUBLY_LINKED_LIST.IS_END                                .  SPEC
  3138.   -- .                                                           .
  3139.   -- .............................................................
  3140.   function Is_End (ID : in LIST_ID) return BOOLEAN;
  3141.   --| Purpose
  3142.   --| Return TRUE if the end of the list has been passed.
  3143.   --|
  3144.   --| Exceptions (none)
  3145.   --| Notes (none)
  3146.    
  3147.   -- .............................................................
  3148.   -- .                                                           .
  3149.   -- .  DOUBLY_LINKED_LIST.IS_FIRST                              .  SPEC
  3150.   -- .                                                           .
  3151.   -- .............................................................
  3152.   function Is_First (ID : in LIST_ID) return BOOLEAN;
  3153.   --| Purpose
  3154.   --| Return TRUE if the current element is the first element.
  3155.   --|
  3156.   --| Exceptions (none)
  3157.   --| Notes (none)
  3158.    
  3159.   -- .............................................................
  3160.   -- .                                                           .
  3161.   -- .  DOUBLY_LINKED_LIST.APPEND_ELEMENT                        .  SPEC
  3162.   -- .                                                           .
  3163.   -- .............................................................
  3164.   procedure Append_Element (ID      : in out LIST_ID;
  3165.                             Element : ELEMENT_OBJECT);
  3166.   --| Purpose
  3167.   --| Append an element after the current element; set the current
  3168.   --| element to this new element.
  3169.   --|
  3170.   --| Exceptions
  3171.   --|   DYNAMIC_MEMORY_ALLOCATION_PROBLEM
  3172.   --|
  3173.   --| Notes (none)
  3174.    
  3175.   -- .............................................................
  3176.   -- .                                                           .
  3177.   -- .  DOUBLY_LINKED_LIST.INSERT_ELEMENT                        .  SPEC
  3178.   -- .                                                           .
  3179.   -- .............................................................
  3180.   procedure Insert_Element (ID      : in out LIST_ID;
  3181.                             Element : ELEMENT_OBJECT);
  3182.   --| Purpose
  3183.   --| Insert an element before the current element; the current
  3184.   --| element remains unchanged.
  3185.   --|
  3186.   --| Exceptions
  3187.   --|   DYNAMIC_MEMORY_ALLOCATION_PROBLEM
  3188.   --|
  3189.   --| Notes (none)
  3190.    
  3191.   -- .............................................................
  3192.   -- .                                                           .
  3193.   -- .  DOUBLY_LINKED_LIST.DELETE_ELEMENT                        .  SPEC
  3194.   -- .                                                           .
  3195.   -- .............................................................
  3196.   procedure Delete_Element (ID : in out LIST_ID);
  3197.   --| Purpose
  3198.   --| Delete the current element; the current element becomes the
  3199.   --| element following the current element.
  3200.   --|
  3201.   --| Exceptions
  3202.   --|   ADVANCE_PAST_END_OF_LIST
  3203.   --|   LIST_IS_EMPTY
  3204.   --|
  3205.   --| Notes (none)
  3206.    
  3207. private
  3208.    type ELEMENT;
  3209.    type ELEMENT_POINTER is access ELEMENT;
  3210.    type ELEMENT is 
  3211.       record
  3212.          Content  : ELEMENT_OBJECT;
  3213.          Next     : ELEMENT_POINTER;
  3214.          Previous : ELEMENT_POINTER;
  3215.       end record;
  3216.    type LIST_ID is 
  3217.       record
  3218.          First              : ELEMENT_POINTER  := null; -- first element
  3219.          Last               : ELEMENT_POINTER  := null; -- last element
  3220.          Current            : ELEMENT_POINTER  := null; -- current element
  3221.          Free               : ELEMENT_POINTER  := null; -- free element list
  3222.          Number_of_Elements : ELEMENT_POSITION := 0; -- number of elements
  3223.          Current_Index      : ELEMENT_POSITION := 0; -- index of current element
  3224.       end record;
  3225.  
  3226. end Doubly_Linked_List;
  3227. --::::::::::
  3228. --dyn.spc
  3229. --::::::::::
  3230. -- *******************************************************
  3231. -- *                                                     *
  3232. -- *  DYN                                                *  SPEC
  3233. -- *                                                     *
  3234. -- *******************************************************
  3235. package Dyn is 
  3236. --| Purpose
  3237. --| Implement a dynamic string object class and provide operations
  3238. --| to manipulate objects of this class.
  3239. --|
  3240. --| Initialization Exceptions (none)
  3241. --| Notes (none)
  3242. --|
  3243. --| Modifications
  3244. --|  This is a package of several string manipulation functions based on
  3245. --| a built-in dynamic STRING type DYN_STRING.  It is an adaptation and
  3246. --| extension of the package proposed by Sylvan Rubin of Ford Aerospace and
  3247. --| Communications Corporation in the Nov/Dec 1984 issue of the Journal of
  3248. --| Pascal, Ada and Modula-2.  Some new functions have been added, and much
  3249. --| of the body code has been rewritten.
  3250. --|
  3251. --| This package is derived from DSTR3.SRC in the Ada Software Repository
  3252. --| DSTR3.SRC was written by R.G. Cleaveland.  The derivation, done by
  3253. --| Richard Conn, was done to remove those general-purpose features of the
  3254. --| package not needed for the PTF project.
  3255.  
  3256.   Max_D_String_Length : constant POSITIVE := 100; 
  3257.     -- This is the maximum LENGTH of a dynamic string implemented with this
  3258.     -- package.  This value is "arbitrary" in that any reasonable number
  3259.     -- equal to or less than the maximum STRING LENGTH permitted by the
  3260.     -- compiler is acceptable.  The specific value above was chosen as a
  3261.     -- compromise between programmer convenience and memory space requirements.
  3262.  
  3263.   subtype DS_POS is INTEGER range 0..MAX_D_STRING_LENGTH;
  3264.   type DYN_STRING is private;
  3265.  
  3266.   STRING_TOO_SHORT: exception;
  3267.  
  3268.   -- ..................................................
  3269.   -- .                                                .
  3270.   -- .  DYN.D_STRING                                  .  SPEC
  3271.   -- .                                                .
  3272.   -- ..................................................
  3273.   function D_String (Char: CHARACTER)  return DYN_STRING;
  3274.   --| Purpose
  3275.   --| Creates a one-byte dynamic string of contents CHAR.
  3276.   --|
  3277.   --| Exceptions (none)
  3278.   --| Notes (none)
  3279.  
  3280.   -- ..................................................
  3281.   -- .                                                .
  3282.   -- .  DYN.D_STRING                                  .  SPEC
  3283.   -- .                                                .
  3284.   -- ..................................................
  3285.   function D_String (Str : STRING)  return DYN_STRING;
  3286.   --| Purpose
  3287.   --| Creates a dynamic string of contents STR.
  3288.   --|
  3289.   --| Exceptions (none)
  3290.   --| Notes (none)
  3291.  
  3292.   -- ..................................................
  3293.   -- .                                                .
  3294.   -- .  DYN.CHAR                                      .  SPEC
  3295.   -- .                                                .
  3296.   -- ..................................................
  3297.   function Char (Dstr  : DYN_STRING;
  3298.                  Posit : POSITIVE := 1) return CHARACTER;
  3299.   --| Purpose
  3300.   --| Return the Nth character of a dynamic string.
  3301.   --|
  3302.   --| Exceptions
  3303.   --|   STRING_TOO_SHORT
  3304.   --|
  3305.   --| Notes (none)
  3306.  
  3307.   -- ..................................................
  3308.   -- .                                                .
  3309.   -- .  DYN.STR                                       .  SPEC
  3310.   -- .                                                .
  3311.   -- ..................................................
  3312.   function Str (Dstr: DYN_STRING) return STRING;
  3313.   --| Purpose
  3314.   --| Return the string whose contents is the value of a dynamic
  3315.   --| string.
  3316.   --|
  3317.   --| Exceptions (none)
  3318.   --| Notes (none)
  3319.   
  3320.   -- ..................................................
  3321.   -- .                                                .
  3322.   -- .  DYN.LENGTH                                    .  SPEC
  3323.   -- .                                                .
  3324.   -- ..................................................
  3325.   function Length (Dstr: DYN_STRING)     return NATURAL;
  3326.   --| Purpose
  3327.   --| Returns the LENGTH of the dynamic string.
  3328.   --|
  3329.   --| Exceptions (none)
  3330.   --| Notes (none)
  3331.  
  3332.   -- ..................................................
  3333.   -- .                                                .
  3334.   -- .  DYN.CLEAR                                     .  SPEC
  3335.   -- .                                                .
  3336.   -- ..................................................
  3337.   procedure Clear (Dstr: in out DYN_STRING);
  3338.   --| Purpose
  3339.   --| Makes DSTR a null string.
  3340.   --|
  3341.   --| Exceptions (none)
  3342.   --| Notes (none)
  3343.  
  3344. private
  3345.   type DYN_STRING is
  3346.     record
  3347.       Size : INTEGER range 0..MAX_D_STRING_LENGTH;
  3348.       Data : STRING(1..MAX_D_STRING_LENGTH);
  3349.     end record;
  3350.  
  3351. end Dyn;
  3352. --::::::::::
  3353. --fof.spc
  3354. --::::::::::
  3355. -- **********************************
  3356. -- *                                *
  3357. -- *  Formatted_Output_File (FOF)   *  SPEC
  3358. -- *                                *
  3359. -- **********************************
  3360. package Formatted_Output_File is
  3361. --| Purpose
  3362. --| Formatted_Output_File manipulates objects of type STRING (text),
  3363. --| placing text into the output file as it is received.
  3364. --| Formatted_Output_File is also used to define the format of the
  3365. --| text (number of lines per page, header, footer, etc.).
  3366. --|
  3367. --| Formatted_Output_File is a form of Report Generator.  Taking in
  3368. --| raw text and other directives (implemented by its procedures),
  3369. --| Formatted_Output_File creates reports (with header lines, footer
  3370. --| lines, page numbering, etc).
  3371. --|
  3372. --| Formatted_Output_File is also referred to as FOF.
  3373. --|
  3374. --| See the test programs for examples of the use of FOF.
  3375. --|
  3376. --| Initialization Exceptions (none)
  3377. --| Notes (none)
  3378. --|
  3379. --| Modifications
  3380. --| 04/22/90   Rick Conn    Initial version from PTF's FOF
  3381. --|                         package of 8/16/89
  3382.  
  3383.   type FILE is
  3384.     private;
  3385.  
  3386.   Maximum_Number_Of_Lines_On_Page
  3387.     : constant
  3388.       := 200;
  3389.  
  3390.   Maximum_Line_Length
  3391.     : constant
  3392.       := 200;
  3393.  
  3394.   Maximum_Number_Of_Header_Footer_Lines
  3395.     : constant
  3396.       := 8;
  3397.  
  3398.   Maximum_Number_Of_Pages
  3399.     : constant
  3400.       := 32000;
  3401.  
  3402.  
  3403.   type PAGE_ATTRIBUTE is
  3404.     ( TOP_MARGIN,       -- Number of lines before first header
  3405.       BOTTOM_MARGIN,    -- Number of lines after last footer
  3406.       LEFT_MARGIN,      -- Column num of the last col before the 1st char
  3407.       RIGHT_MARGIN,     -- Column number of the last char of the line
  3408.       LEFT_INDENT,      -- Number of columns to indent from LEFT_MARGIN
  3409.       RIGHT_INDENT,     -- Number of columns to indent from RIGHT_MARGIN
  3410.       TOTAL_LINES,      -- Number of lines on a page
  3411.       HEADER_LINES,     -- Number of lines in the header
  3412.       FOOTER_LINES,     -- Number of lines in the footer
  3413.       LINE_SPACING,     -- Number of blank lines after each text line
  3414.       PAGE_OFFSET,      -- Number of columns to offset each line
  3415.       TEMP_INDENT       -- Number of columns to indent next line only
  3416.                         -- (this is an absolute value, not influenced
  3417.                         --  by the LEFT_MARGIN or LEFT_INDENT settings)
  3418.     );
  3419.  
  3420.   type LINE_ATTRIBUTE is
  3421.     ( BOLD,                     -- Make words come out bold (overstrike)
  3422.       CENTER,                   -- Center lines (Put_Line with No Fill)
  3423.       FILL,                     -- Successively place words into an output
  3424.                                 --  line until the next word will not fit
  3425.                                 --  between the left and right margins
  3426.                                 --  (with indents)
  3427.       FILL_STATE_BEFORE_CENTER, -- Save area for FILL
  3428.       JUSTIFY,                  -- Fill output line to RIGHT_MARGIN -
  3429.                                 --  RIGHT_INDENT with spaces between words
  3430.       PAGING,                   -- Break output on page boundaries,
  3431.                                 --  outputting footer, bottom margin,
  3432.                                 --  top margin, and header
  3433.       UNDERLINE,                -- Underline words
  3434.       UNDERLINE_PUNCT,          -- If ON, underline punctuation
  3435.       USE_FORM_FEED             -- Use form feeds to eject pages
  3436.     );
  3437.  
  3438.   type PAGE_ATTRIBUTE_LIST is
  3439.     array (PAGE_ATTRIBUTE)
  3440.       of NATURAL;
  3441.  
  3442.   type OFF_ON is
  3443.     ( OFF, ON );
  3444.  
  3445.   type LINE_ATTRIBUTE_LIST is
  3446.     array (LINE_ATTRIBUTE)
  3447.       of OFF_ON;
  3448.  
  3449.   Page_Attribute_Defaults
  3450.     : constant PAGE_ATTRIBUTE_LIST
  3451.       := (
  3452.         TOP_MARGIN     => 4,
  3453.         BOTTOM_MARGIN  => 4,
  3454.         LEFT_MARGIN    => 12,
  3455.         RIGHT_MARGIN   => 90,
  3456.         LEFT_INDENT    => 0,
  3457.         RIGHT_INDENT   => 0,
  3458.         TOTAL_LINES    => 66,
  3459.         HEADER_LINES   => 2,
  3460.         FOOTER_LINES   => 2,
  3461.         LINE_SPACING   => 0,
  3462.         PAGE_OFFSET    => 0,
  3463.         TEMP_INDENT    => 0 );
  3464.  
  3465.   Line_Attribute_Defaults
  3466.     : constant LINE_ATTRIBUTE_LIST
  3467.       := (
  3468.         BOLD           => OFF,
  3469.         CENTER         => OFF,
  3470.         FILL           => ON,
  3471.         FILL_STATE_BEFORE_CENTER => ON,
  3472.         JUSTIFY        => ON,
  3473.         PAGING         => ON,
  3474.         UNDERLINE      => OFF,
  3475.         UNDERLINE_PUNCT => OFF,
  3476.         USE_FORM_FEED  => ON );
  3477.  
  3478.  
  3479.   Page_Number_Id_Default
  3480.     : constant CHARACTER
  3481.       := '#';
  3482.  
  3483.   type LINE_NUMBER is
  3484.     new INTEGER range 0 .. Maximum_Number_Of_Lines_On_Page;
  3485.  
  3486.   type HEADER_FOOTER_LINE is                     -- H/F line numbers
  3487.     new INTEGER range 1 .. Maximum_Number_Of_Header_Footer_Lines;
  3488.  
  3489.   type PAGE_NUMBER is
  3490.     new INTEGER range 0 .. Maximum_Number_Of_Pages;
  3491.  
  3492.   type STATUS is                                 -- for Open
  3493.     ( OK, NOT_OK );
  3494.  
  3495.   type PAGE_SIDE is                              -- for margins and indents
  3496.     ( LEFT_SIDE, RIGHT_SIDE );
  3497.  
  3498.   type PAGE_KIND is                              -- for headers and footers
  3499.     ( EVEN_PAGES, ODD_PAGES, ALL_PAGES );
  3500.  
  3501.   type NUMERIC_FORMAT is                         -- for page numbers
  3502.     ( ARABIC, LOWER_ROMAN, UPPER_ROMAN );
  3503.  
  3504.   Range_Error
  3505.     : exception;
  3506.  
  3507.   File_Not_Open
  3508.     : exception;
  3509.  
  3510.   -- ..................................
  3511.   -- .                                .
  3512.   -- .  FOF.Open                      .  SPEC
  3513.   -- .                                .
  3514.   -- ..................................
  3515.   procedure Open
  3516.     ( Item           : in out FILE;
  3517.       File_Name      : in STRING;
  3518.       Result         : out STATUS );
  3519.   --| Purpose
  3520.   --| Open the formatted output file for subsequent processing.
  3521.   --|
  3522.   --| Exceptions (none)
  3523.   --| Notes (none)
  3524.  
  3525.   -- ..................................
  3526.   -- .                                .
  3527.   -- .  FOF.Close                     .  SPEC
  3528.   -- .                                .
  3529.   -- ..................................
  3530.   procedure Close
  3531.     ( Item           : in FILE );
  3532.   --| Purpose
  3533.   --| Close the formatted output file.
  3534.   --|
  3535.   --| Exceptions
  3536.   --| File_Not_Open
  3537.   --|
  3538.   --| Notes (none)
  3539.  
  3540.   -- ..................................
  3541.   -- .                                .
  3542.   -- .  FOF.Put_Invisible_Word        .  SPEC
  3543.   -- .                                .
  3544.   -- ..................................
  3545.   procedure Put_Invisible_Word
  3546.     ( Item           : in FILE;
  3547.       What           : in STRING );
  3548.   --| Purpose
  3549.   --| Add a word to the current line and do not increment the
  3550.   --| character count.
  3551.   --|
  3552.   --| Exceptions
  3553.   --| File_Not_Open
  3554.   --|
  3555.   --| Notes (none)
  3556.  
  3557.   -- ..................................
  3558.   -- .                                .
  3559.   -- .  FOF.Put_Word                  .  SPEC
  3560.   -- .                                .
  3561.   -- ..................................
  3562.   procedure Put_Word
  3563.     ( Item           : in FILE;
  3564.       What           : in STRING );
  3565.   --| Purpose
  3566.   --| Add a word to the current line.
  3567.   --|
  3568.   --| Exceptions
  3569.   --| File_Not_Open
  3570.   --|
  3571.   --| Notes (none)
  3572.  
  3573.   -- ..................................
  3574.   -- .                                .
  3575.   -- .  FOF.Put_Line                  .  SPEC
  3576.   -- .                                .
  3577.   -- ..................................
  3578.   procedure Put_Line
  3579.     ( Item           : in FILE;
  3580.       What           : in STRING );
  3581.   --| Purpose
  3582.   --| Add a line to the current page.  If line break, insert blank
  3583.   --| lines as per LINE_SPACING.
  3584.   --|
  3585.   --| Exceptions
  3586.   --| File_Not_Open
  3587.   --|
  3588.   --| Notes (none)
  3589.  
  3590.   -- ..................................
  3591.   -- .                                .
  3592.   -- .  FOF.Break_Line                .  SPEC
  3593.   -- .                                .
  3594.   -- ..................................
  3595.   procedure Break_Line
  3596.     ( Item           : in FILE );
  3597.   --| Purpose
  3598.   --| Break the current line (if it contains any words, output them).
  3599.   --| Insert blank lines as per the LINE_SPACING setting.
  3600.   --|
  3601.   --| Exceptions
  3602.   --| File_Not_Open
  3603.   --|
  3604.   --| Notes (none)
  3605.  
  3606.   -- ..................................
  3607.   -- .                                .
  3608.   -- .  FOF.Current_Line              .  SPEC
  3609.   -- .                                .
  3610.   -- ..................................
  3611.   function Current_Line
  3612.     ( Item           : in FILE )
  3613.       return LINE_NUMBER;
  3614.   --| Purpose
  3615.   --| Return the number of the current line.
  3616.   --|
  3617.   --| Exceptions
  3618.   --| File_Not_Open
  3619.   --|
  3620.   --| Notes (none)
  3621.  
  3622.   -- ..................................
  3623.   -- .                                .
  3624.   -- .  FOF.Skip                      .  SPEC
  3625.   -- .                                .
  3626.   -- ..................................
  3627.   procedure Skip
  3628.     ( Item           : in FILE;
  3629.       Number_Of_Lines : in LINE_NUMBER := 1 );
  3630.   --| Purpose
  3631.   --| Skip Number_Of_Lines in the output after first issuing a Break_Line.
  3632.   --| LINE_SPACING influences the actual number of lines skipped.
  3633.   --|
  3634.   --| Exceptions
  3635.   --| File_Not_Open
  3636.   --|
  3637.   --| Notes (none)
  3638.  
  3639.   -- ..................................
  3640.   -- .                                .
  3641.   -- .  FOF.Break_Page                .  SPEC
  3642.   -- .                                .
  3643.   -- ..................................
  3644.   procedure Break_Page
  3645.     ( Item           : in FILE );
  3646.   --| Purpose
  3647.   --| If there is anything on the current page, output it and advance
  3648.   --| to the next page.
  3649.   --|
  3650.   --| Exceptions
  3651.   --| File_Not_Open
  3652.   --|
  3653.   --| Notes (none)
  3654.  
  3655.   -- ..................................
  3656.   -- .                                .
  3657.   -- .  FOF.Break_Page                .  SPEC
  3658.   -- .                                .
  3659.   -- ..................................
  3660.   procedure Break_Page
  3661.     ( Item           : in FILE;
  3662.       New_Page_Num   : in PAGE_NUMBER );
  3663.   --| Purpose
  3664.   --| If there is anything on the current page, output it and advance
  3665.   --| to the next page.  Set the number of the next page to New_Page_Num.
  3666.   --|
  3667.   --| Exceptions
  3668.   --| File_Not_Open
  3669.   --|
  3670.   --| Notes (none)
  3671.  
  3672.   -- ..................................
  3673.   -- .                                .
  3674.   -- .  FOF.Current_Page              .  SPEC
  3675.   -- .                                .
  3676.   -- ..................................
  3677.   function Current_Page
  3678.     ( Item           : in FILE )
  3679.       return PAGE_NUMBER;
  3680.   --| Purpose
  3681.   --| Return the number of the current page.
  3682.   --|
  3683.   --| Exceptions
  3684.   --| File_Not_Open
  3685.   --|
  3686.   --| Notes (none)
  3687.  
  3688.   -- ..................................
  3689.   -- .                                .
  3690.   -- .  FOF.Current_Page              .  SPEC
  3691.   -- .                                .
  3692.   -- ..................................
  3693.   function Current_Page
  3694.     ( Item           : in FILE )
  3695.       return STRING;
  3696.   --| Purpose
  3697.   --| Return the number of the current page as a string.
  3698.   --|
  3699.   --| Exceptions
  3700.   --| File_Not_Open
  3701.   --|
  3702.   --| Notes (none)
  3703.  
  3704.   -- ..................................
  3705.   -- .                                .
  3706.   -- .  FOF.Set_Page_Number_Format    .  SPEC
  3707.   -- .                                .
  3708.   -- ..................................
  3709.   procedure Set_Page_Number_Format
  3710.     ( Item           : in FILE;
  3711.       To             : in NUMERIC_FORMAT;
  3712.       Format_String  : in STRING );
  3713.   --| Purpose
  3714.   --| Set the format of the page number.  If the Format_String is not
  3715.   --| null, the page numbers in the headers and footers will appear as
  3716.   --| indicated (with the literal number substituted for # characters).
  3717.   --|
  3718.   --| Exceptions
  3719.   --| File_Not_Open
  3720.   --|
  3721.   --| Notes (none)
  3722.  
  3723.   -- ..................................
  3724.   -- .                                .
  3725.   -- .  FOF.Set_Page_Attribute        .  SPEC
  3726.   -- .                                .
  3727.   -- ..................................
  3728.   procedure Set_Page_Attribute
  3729.     ( Item           : in FILE;
  3730.       What           : in PAGE_ATTRIBUTE;
  3731.       To             : in NATURAL );
  3732.   --| Purpose
  3733.   --| Set a specified page attribute.
  3734.   --|
  3735.   --| Exceptions
  3736.   --| Range_Error    raised if To is outside the range for What
  3737.   --| File_Not_Open
  3738.   --|
  3739.   --| Notes (none)
  3740.  
  3741.   -- ..................................
  3742.   -- .                                .
  3743.   -- .  FOF.Set_Line_Attribute        .  SPEC
  3744.   -- .                                .
  3745.   -- ..................................
  3746.   procedure Set_Line_Attribute
  3747.     ( Item           : in FILE;
  3748.       What           : in LINE_ATTRIBUTE;
  3749.       To             : in OFF_ON );
  3750.   --| Purpose
  3751.   --| Turn off or on the indicated attribute for the current and
  3752.   --| following lines.
  3753.   --|
  3754.   --| Exceptions
  3755.   --| File_Not_Open
  3756.   --|
  3757.   --| Notes (none)
  3758.  
  3759.   -- ..................................
  3760.   -- .                                .
  3761.   -- .  FOF.Get_Page_Attribute        .  SPEC
  3762.   -- .                                .
  3763.   -- ..................................
  3764.   function Get_Page_Attribute
  3765.     ( Item           : in FILE;
  3766.       What           : in PAGE_ATTRIBUTE )
  3767.       return NATURAL;
  3768.   --| Purpose
  3769.   --| Get a specified page attribute.
  3770.   --|
  3771.   --| Exceptions
  3772.   --| File_Not_Open
  3773.   --|
  3774.   --| Notes (none)
  3775.  
  3776.   -- ..................................
  3777.   -- .                                .
  3778.   -- .  FOF.Get_Line_Attribute        .  SPEC
  3779.   -- .                                .
  3780.   -- ..................................
  3781.   function Get_Line_Attribute
  3782.     ( Item           : in FILE;
  3783.       What           : in LINE_ATTRIBUTE )
  3784.       return OFF_ON;
  3785.   --| Purpose
  3786.   --| Get the indicated attribute for the current and
  3787.   --| following lines.
  3788.   --|
  3789.   --| Exceptions
  3790.   --| File_Not_Open
  3791.   --|
  3792.   --| Notes (none)
  3793.  
  3794.   -- ..................................
  3795.   -- .                                .
  3796.   -- .  FOF.Test_Page                 .  SPEC
  3797.   -- .                                .
  3798.   -- ..................................
  3799.   function Test_Page
  3800.     ( Item           : in FILE;
  3801.       Number_Of_Lines : in LINE_NUMBER )
  3802.       return BOOLEAN;
  3803.   --| Purpose
  3804.   --| Return TRUE if Number_Of_Lines is remaining on the current page.
  3805.   --|
  3806.   --| Exceptions
  3807.   --| File_Not_Open
  3808.   --|
  3809.   --| Notes (none)
  3810.  
  3811.   -- ..................................
  3812.   -- .                                .
  3813.   -- .  FOF.Set_Footer_Line           .  SPEC
  3814.   -- .                                .
  3815.   -- ..................................
  3816.   procedure Set_Footer_Line
  3817.     ( Item           : in FILE;
  3818.       Class          : in PAGE_KIND;
  3819.       Number         : in HEADER_FOOTER_LINE;
  3820.       Left_Text      : in STRING;
  3821.       Center_Text    : in STRING;
  3822.       Right_Text     : in STRING );
  3823.   --| Purpose
  3824.   --| Store a footer line for EVEN, ODD, or ALL pages.
  3825.   --| The footer line is dynamically adjusted, based on the left and right
  3826.   --| margin settings.  The strings Left, Center, and Right are left-
  3827.   --| justified, centered, and right-justified in the indicated footer
  3828.   --| line, respectively.
  3829.   --|
  3830.   --| Exceptions
  3831.   --| File_Not_Open
  3832.   --|
  3833.   --| Notes (none)
  3834.  
  3835.   -- ..................................
  3836.   -- .                                .
  3837.   -- .  FOF.Set_Header_Line           .  SPEC
  3838.   -- .                                .
  3839.   -- ..................................
  3840.   procedure Set_Header_Line
  3841.     ( Item           : in FILE;
  3842.       Class          : in PAGE_KIND;
  3843.       Number         : in HEADER_FOOTER_LINE;
  3844.       Left_Text      : in STRING;
  3845.       Center_Text    : in STRING;
  3846.       Right_Text     : in STRING );
  3847.   --| Purpose
  3848.   --| Store a header line for EVEN, ODD, or ALL pages.
  3849.   --| The header line is dynamically adjusted, based on the left and right
  3850.   --| margin settings.  The strings Left, Center, and Right are left-
  3851.   --| justified, centered, and right-justified in the indicated header
  3852.   --| line, respectively.
  3853.   --|
  3854.   --| Exceptions
  3855.   --| File_Not_Open
  3856.   --|
  3857.   --| Notes (none)
  3858.  
  3859.   -- ..................................
  3860.   -- .                                .
  3861.   -- .  FOF.Set_Page_Number_Id        .  SPEC
  3862.   -- .                                .
  3863.   -- ..................................
  3864.   procedure Set_Page_Number_Id
  3865.     ( Item           : in FILE;
  3866.       To             : in CHARACTER );
  3867.   --| Purpose
  3868.   --| Set the character used to represent the page number in the
  3869.   --| header and footer lines of the output file.
  3870.   --|
  3871.   --| Exceptions
  3872.   --| File_Not_Open
  3873.   --|
  3874.   --| Notes (none)
  3875.  
  3876.   -- ..................................
  3877.   -- .                                .
  3878.   -- .  FOF.Set_Page_Number_Format    .  SPEC
  3879.   -- .                                .
  3880.   -- ..................................
  3881.   procedure Set_Page_Number_Format
  3882.     ( Item           : in FILE;
  3883.       To             : in NUMERIC_FORMAT );
  3884.   --| Purpose
  3885.   --| Set the format used to represent the page number in the
  3886.   --| header and footer lines of the output file.
  3887.   --|
  3888.   --| Exceptions
  3889.   --| File_Not_Open
  3890.   --|
  3891.   --| Notes (none)
  3892.  
  3893.   -- ..................................
  3894.   -- .                                .
  3895.   -- .  FOF.Page_Number_Format        .  SPEC
  3896.   -- .                                .
  3897.   -- ..................................
  3898.   function Page_Number_Format
  3899.     ( Item           : in FILE )
  3900.     return NUMERIC_FORMAT;
  3901.   --| Purpose
  3902.   --| Get the format used to represent the page number in the
  3903.   --| header and footer lines of the output file.
  3904.   --|
  3905.   --| Exceptions
  3906.   --| File_Not_Open
  3907.   --|
  3908.   --| Notes (none)
  3909.  
  3910. private -- Formatted_Output_File
  3911.  
  3912.   type FILE_OBJECT;
  3913.   type FILE is
  3914.     access FILE_OBJECT;
  3915.  
  3916. end Formatted_Output_File;
  3917. --::::::::::
  3918. --hashfcns.spc
  3919. --::::::::::
  3920. -- *********************************************************
  3921. -- *                                                       *
  3922. -- *  Hashing_Functions_PKG                                *  SPEC
  3923. -- *                                                       *
  3924. -- *********************************************************
  3925. package Hashing_Functions_PKG is
  3926. --| Purpose
  3927. --| Provide a string hashing function.
  3928. --|
  3929. --| Initialization Exceptions (none)
  3930. --| Notes (none)
  3931. --|
  3932. --| Modifications
  3933. --| Author: Bill Toscano and Michael Gordon, Intermetrics
  3934.  
  3935.   generic
  3936.     Prime_Num: in POSITIVE;  -- Required to be prime
  3937.   function Hash_String (S: STRING) return NATURAL;
  3938.   --| Purpose
  3939.   --| Produces a uniform distribution over the range 0..prime - 1.
  3940.   --|
  3941.   --| Exceptions (none)
  3942.   --| Notes (none)
  3943.     
  3944. end Hashing_Functions_PKG;
  3945. --::::::::::
  3946. --in.spc
  3947. --::::::::::
  3948. -- **********************************
  3949. -- *                                *
  3950. -- *  Input_File                    *  SPEC
  3951. -- *                                *
  3952. -- **********************************
  3953. package Input_File is
  3954. --| Purpose
  3955. --| Input_File implements an abstract data type of an input file.
  3956. --| Input_File offers an abstraction that can be made more efficient
  3957. --| by not using Text_IO (and having its associated overhead imposed)
  3958. --| if possible,
  3959. --|
  3960. --| Initialization Exceptions (none)
  3961. --| Notes (none)
  3962. --|
  3963. --| Modifications
  3964. --| 08/16/89  Rick Conn    Initial Version
  3965.  
  3966.   type FILE_TYPE is
  3967.     private;
  3968.  
  3969.   Cannot_Open_Input_File
  3970.     : exception;
  3971.   Read_Error
  3972.     : exception;
  3973.  
  3974.   -- ..................................
  3975.   -- .                                .
  3976.   -- .  Input_File.Open               .  SPEC
  3977.   -- .                                .
  3978.   -- ..................................
  3979.   procedure Open
  3980.     ( Id             : in out FILE_TYPE;
  3981.       File_Name      : in STRING );
  3982.   --| Purpose
  3983.   --| Open an existing FILE_TYPE object.
  3984.   --|
  3985.   --| Exceptions
  3986.   --|   Cannot_Open_Input_File
  3987.   --|
  3988.   --| Notes (none)
  3989.  
  3990.   -- ..................................
  3991.   -- .                                .
  3992.   -- .  Input_File.Get_Line           .  SPEC
  3993.   -- .                                .
  3994.   -- ..................................
  3995.   procedure Get_Line
  3996.     ( Id             : in out FILE_TYPE;
  3997.       Item           : out STRING;
  3998.       Last           : out NATURAL );
  3999.   --| Purpose
  4000.   --| Get_Line reads an Item to the FILE_TYPE object.
  4001.   --|
  4002.   --| Exceptions
  4003.   --|   Read_Error
  4004.   --|
  4005.   --| Notes (none)
  4006.  
  4007.   -- ..................................
  4008.   -- .                                .
  4009.   -- .  Input_File.End_Of_File        .  SPEC
  4010.   -- .                                .
  4011.   -- ..................................
  4012.   function End_Of_File
  4013.     ( Id             : in FILE_TYPE )
  4014.       return BOOLEAN;
  4015.   --| Purpose
  4016.   --| End_Of_File returns TRUE if the FILE_TYPE object is empty or
  4017.   --| no more data is in it.
  4018.   --|
  4019.   --| Exceptions
  4020.   --|   Read_Error
  4021.   --|
  4022.   --| Notes (none)
  4023.  
  4024.   -- ..................................
  4025.   -- .                                .
  4026.   -- .  Input_File.Close              .  SPEC
  4027.   -- .                                .
  4028.   -- ..................................
  4029.   procedure Close
  4030.     ( Id             : in out FILE_TYPE );
  4031.   --| Purpose
  4032.   --| Close closes input from the FILE_TYPE object.
  4033.   --|
  4034.   --| Exceptions (none)
  4035.   --| Notes (none)
  4036.  
  4037. private -- Input_File
  4038.   type FILE_OBJECT;
  4039.   type FILE_TYPE is
  4040.     access FILE_OBJECT;
  4041.  
  4042. end Input_File;
  4043. --::::::::::
  4044. --lists.spc
  4045. --::::::::::
  4046. -- *********************************************
  4047. -- *                                           *
  4048. -- *  LISTS                                    *  SPEC
  4049. -- *                                           *
  4050. -- *********************************************
  4051. generic
  4052.       type ITEMTYPE is private;  -- This is the data being manipulated.
  4053.       with function Equal (X,Y: in ITEMTYPE) return BOOLEAN is "=";
  4054.                                  -- This allows the user to define
  4055.                                  -- equality on ItemType.  For instance
  4056.                                  -- if ItemType is an abstract type
  4057.                                  -- then equality is defined in terms of
  4058.                                  -- the abstract type.  If this function
  4059.                                  -- is not provided equality defaults to
  4060.                                  -- =.
  4061. package Lists is
  4062. --| Purpose
  4063. --| This package provides singly linked lists with elements of type
  4064. --| ItemType, where ItemType is specified by a generic parameter.
  4065. --| 
  4066. --| When this package is instantiated, it provides a linked list type for
  4067. --| lists of objects of type ItemType, which can be any desired type.  A
  4068. --| complete set of operations for manipulation, and releasing
  4069. --| those lists is also provided.  For instance, to make lists of strings,
  4070. --| all that is necessary is:
  4071. --|
  4072. --| type StringType is string(1..10);
  4073. --|
  4074. --| package Str_List is new Lists(StringType); use Str_List;
  4075. --| 
  4076. --|    L:List;
  4077. --|    S:StringType;
  4078. --|
  4079. --| Then to add a string S, to the list L, all that is necessary is
  4080. --|
  4081. --|    L := Create;
  4082. --|    Attach(S,L);
  4083. --| 
  4084. --| Initialization Exceptions (none)
  4085. --| Notes (none)
  4086. --|
  4087. --| Modifications
  4088. --| Programmer Buddy Altus, Intermetrics
  4089.  
  4090.           type LIST       is private;
  4091.           type LISTITER   is private;
  4092.  
  4093.     CircularList     :exception;     -- Raised if an attemp is made to
  4094.                                      -- create a circular list.  This
  4095.                                      -- results when a list is attempted
  4096.                                      -- to be attached to itself.
  4097.      
  4098.     EmptyList        :exception;     -- Raised if an attemp is made to
  4099.                                      -- manipulate an empty list.
  4100.  
  4101.     ItemNotPresent   :exception;     -- Raised if an attempt is made to
  4102.                                      -- remove an element from a list in
  4103.                                      -- which it does not exist.
  4104.  
  4105.     NoMore           :exception;     -- Raised if an attemp is made to
  4106.                                      -- get the next element from a list
  4107.                                      -- after iteration is complete.
  4108.  
  4109.   -- .......................................................
  4110.   -- .                                                     .
  4111.   -- .  LISTS.ATTACH                                       .  SPEC
  4112.   -- .                                                     .
  4113.   -- .......................................................
  4114.   procedure Attach (List1: in out LIST; List2: in LIST);
  4115.   --| Purpose
  4116.   --| Appends List2 to List1.  This makes the next field of the last element
  4117.   --| of List1 refer to List2.  This can possibly change the value of List1
  4118.   --| if List1 is an empty list.  This causes sharing of lists.  Thus if
  4119.   --| user Destroys List1 then List2 will be a dangling reference.
  4120.   --| This procedure raises CircularList if List1 equals List2.  If it is 
  4121.   --| necessary to Attach a list to itself first make a copy of the list and 
  4122.   --| attach the copy.
  4123.   --|
  4124.   --| Exceptions
  4125.   --|   CircularList
  4126.   --|
  4127.   --| Notes
  4128.  
  4129.   -- .......................................................
  4130.   -- .                                                     .
  4131.   -- .  LISTS.ATTACH                                       .  SPEC
  4132.   -- .                                                     .
  4133.   -- .......................................................
  4134.   function Attach (Element1: in ITEMTYPE; Element2: in ITEMTYPE) return LIST;
  4135.   --| Purpose
  4136.   --| This creates a list containing the two elements in the order
  4137.   --| specified.
  4138.   --|
  4139.   --| Exceptions (none)
  4140.   --| Notes (none)
  4141.  
  4142.   -- .......................................................
  4143.   -- .                                                     .
  4144.   -- .  LISTS.ATTACH                                       .  SPEC
  4145.   -- .                                                     .
  4146.   -- .......................................................
  4147.   procedure Attach (L: in out LIST; Element: in ITEMTYPE);
  4148.   --| Purpose
  4149.   --| Appends Element onto the end of the list L.  If L is empty then this
  4150.   --| may change the value of L.
  4151.   --|
  4152.   --| Exceptions (none)
  4153.   --| Notes (none)
  4154.  
  4155.   -- .......................................................
  4156.   -- .                                                     .
  4157.   -- .  LISTS.ATTACH                                       .  SPEC
  4158.   -- .                                                     .
  4159.   -- .......................................................
  4160.   procedure Attach (Element: in ITEMTYPE; L: in  out LIST);
  4161.   --| Purpose
  4162.   --| This prepends list L with Element (makes Element the first item in
  4163.   --| list L).
  4164.   --|
  4165.   --| Exceptions (none)
  4166.   --| Notes (none)
  4167.  
  4168.   -- .......................................................
  4169.   -- .                                                     .
  4170.   -- .  LISTS.ATTACH                                       .  SPEC
  4171.   -- .                                                     .
  4172.   -- .......................................................
  4173.   function Attach (List1: in LIST; List2: in LIST) return LIST;
  4174.   --| Purpose
  4175.   --| This returns a list which is List1 attached to List2.  If it is desired
  4176.   --| to make List1 be the new attached list the following ada code should be
  4177.   --| used.
  4178.   --|  
  4179.   --| List1 := Attach (List1, List2);
  4180.   --|
  4181.   --| This procedure raises CircularList if List1 equals List2.  If it is 
  4182.   --| necessary to Attach a list to itself first make a copy of the list and 
  4183.   --| attach the copy.
  4184.   --|
  4185.   --| Exceptions
  4186.   --|   CircularList
  4187.   --|
  4188.   --| Notes (none)
  4189.  
  4190.   -- .......................................................
  4191.   -- .                                                     .
  4192.   -- .  LISTS.ATTACH                                       .  SPEC
  4193.   -- .                                                     .
  4194.   -- .......................................................
  4195.   function Attach (Element: in ITEMTYPE; L: in LIST) return LIST;
  4196.   --| Purpose
  4197.   --| Returns a new list which is headed by Element and followed by L.
  4198.   --|
  4199.   --| Exceptions (none)
  4200.   --| Notes (none)
  4201.  
  4202.   -- .......................................................
  4203.   -- .                                                     .
  4204.   -- .  LISTS.ATTACH                                       .  SPEC
  4205.   -- .                                                     .
  4206.   -- .......................................................
  4207.   function Attach (L: in LIST; Element: in ITEMTYPE) return LIST;
  4208.   --| Purpose
  4209.   --| Returns a new list which is L followed by Element.
  4210.   --|
  4211.   --| Exceptions (none)
  4212.   --| Notes (none)
  4213.  
  4214.   -- .......................................................
  4215.   -- .                                                     .
  4216.   -- .  LISTS.COPY                                         .  SPEC
  4217.   -- .                                                     .
  4218.   -- .......................................................
  4219.   function Copy (L: in LIST) return LIST;
  4220.   --| Purpose
  4221.   --| Returns a copy of L.
  4222.   --|
  4223.   --| Exceptions (none)
  4224.   --| Notes (none)
  4225.  
  4226.   -- .......................................................
  4227.   -- .                                                     .
  4228.   -- .  LISTS.COPYDEEP                                     .  SPEC
  4229.   -- .                                                     .
  4230.   -- .......................................................
  4231.   generic
  4232.         with function Copy (I: in ITEMTYPE) return ITEMTYPE;
  4233.   function CopyDeep (L: in LIST) return LIST;
  4234.   --| Purpose
  4235.   --| This produces a new list whose elements have been duplicated using
  4236.   --| the Copy function provided by the user.  This is helpful if the type
  4237.   --| of a list is an abstract data type.
  4238.   --|
  4239.   --| Exceptions (none)
  4240.   --| Notes (none)
  4241.  
  4242.   -- .......................................................
  4243.   -- .                                                     .
  4244.   -- .  LISTS.CREATE                                       .  SPEC
  4245.   -- .                                                     .
  4246.   -- .......................................................
  4247.   function Create return LIST;
  4248.   --| Purpose
  4249.   --| Returns an empty, initialized list.
  4250.   --|
  4251.   --| Exceptions (none)
  4252.   --| Notes (none)
  4253.  
  4254.   -- .......................................................
  4255.   -- .                                                     .
  4256.   -- .  LISTS.DELETEHEAD                                   .  SPEC
  4257.   -- .                                                     .
  4258.   -- .......................................................
  4259.   procedure DeleteHead (L: in out LIST); 
  4260.   --| Purpose
  4261.   --| This will return the space occupied by the first element in the list
  4262.   --| to the heap.  If sharing exists between lists this procedure
  4263.   --| could leave a dangling reference.  If L is empty, EmptyList will be
  4264.   --| raised.
  4265.   --|
  4266.   --| Exceptions
  4267.   --|   EmptyList
  4268.   --|
  4269.   --| Notes (none)
  4270.  
  4271.   -- .......................................................
  4272.   -- .                                                     .
  4273.   -- .  LISTS.DELETEITEM                                   .  SPEC
  4274.   -- .                                                     .
  4275.   -- .......................................................
  4276.   procedure DeleteItem (L: in out LIST; Element: in ITEMTYPE);
  4277.   --| Purpose
  4278.   --| Removes the first element of the list equal to Element.  If there is
  4279.   --| not an element equal to Element, then ItemNotPresent is raised.
  4280.   --|
  4281.   --| This operation is destructive; it returns the storage occupied by
  4282.   --| the elements being deleted.
  4283.   --|
  4284.   --| Exceptions
  4285.   --|   ItemNotPresent
  4286.   --|
  4287.   --| Notes (none)
  4288.  
  4289.   -- .......................................................
  4290.   -- .                                                     .
  4291.   -- .  LISTS.DELETEITEM                                   .  SPEC
  4292.   -- .                                                     .
  4293.   -- .......................................................
  4294.   function DeleteItem (L: in LIST; Element: in ITEMTYPE) return LIST;
  4295.   --| Purpose
  4296.   --| This returns the List L with the first occurrence of Element removed.
  4297.   --|
  4298.   --| Exceptions (none)
  4299.   --| Notes (none)
  4300.  
  4301.   -- .......................................................
  4302.   -- .                                                     .
  4303.   -- .  LISTS.DELETEITEMS                                  .  SPEC
  4304.   -- .                                                     .
  4305.   -- .......................................................
  4306.   function DeleteItems (L: in LIST; Element: in ITEMTYPE) return LIST;
  4307.   --| Purpose
  4308.   --| This function returns a copy of the list L which has all elements which
  4309.   --| have value Element removed.
  4310.   --|
  4311.   --| Exceptions (none)
  4312.   --| Notes (none)
  4313.  
  4314.   -- .......................................................
  4315.   -- .                                                     .
  4316.   -- .  LISTS.DELETEITEMS                                  .  SPEC
  4317.   -- .                                                     .
  4318.   -- .......................................................
  4319.   procedure DeleteItems (L: in out LIST; Element: in ITEMTYPE);
  4320.   --| Purpose
  4321.   --| This procedure removes all occurrences of Element from the List L.  This
  4322.   --| is a destructive procedure.
  4323.   --|
  4324.   --| Exceptions (none)
  4325.   --| Notes (none)
  4326.  
  4327.   -- .......................................................
  4328.   -- .                                                     .
  4329.   -- .  LISTS.DESTROY                                      .  SPEC
  4330.   -- .                                                     .
  4331.   -- .......................................................
  4332.   procedure Destroy (L: in out LIST);
  4333.   --| Purpose
  4334.   --| This returns to the heap all the storage that a list occupies.  Keep in
  4335.   --| mind if there exists sharing between lists then this operation can leave
  4336.   --| dangling references.
  4337.   --|
  4338.   --| Exceptions (none)
  4339.   --| Notes (none)
  4340.  
  4341.   -- .......................................................
  4342.   -- .                                                     .
  4343.   -- .  LISTS.DESTROYDEEP                                  .  SPEC
  4344.   -- .                                                     .
  4345.   -- .......................................................
  4346.   generic
  4347.     with procedure Dispose (I :in out ITEMTYPE); 
  4348.   procedure DestroyDeep (L :in out LIST);
  4349.   --| Purpose
  4350.   --| This procedure is used to destroy a list and all the objects contained
  4351.   --| in an element of the list.  For example if L is a list of lists
  4352.   --| then destroy L does not destroy the lists which are elements of L.
  4353.   --| DestroyDeep will now destroy L and all the objects in the elements of L.
  4354.   --| The produce Dispose is a procedure which will destroy the objects which
  4355.   --| comprise an element of a list.  For example if package  L was  a list
  4356.   --| of lists then Dispose for L would be the Destroy of list type package L was
  4357.   --| instantiated with.
  4358.   --| 
  4359.   --| This procedure requires no sharing between elements of lists. 
  4360.   --| For example, if L_int is a list of integers and L_of_L_int is a list 
  4361.   --| of lists of integers and two elements of L_of_L_int have the same value
  4362.   --| then doing a DestroyDeep will cause an access violation to be raised.  
  4363.   --| The best way to avoid this is not to have sharing between list elements
  4364.   --| or use copy functions when adding to the list of lists.
  4365.   --|
  4366.   --| Exceptions (none)
  4367.   --| Notes (none)
  4368.  
  4369.   -- .......................................................
  4370.   -- .                                                     .
  4371.   -- .  LISTS.FIRSTVALUE                                   .  SPEC
  4372.   -- .                                                     .
  4373.   -- .......................................................
  4374.   function FirstValue (L: in LIST) return ITEMTYPE;
  4375.   --| Purpose
  4376.   --| This returns the Item in the first position in the list.  If the list
  4377.   --| is empty EmptyList is raised.
  4378.   --|
  4379.   --| Exceptions
  4380.   --|   EmptyList
  4381.   --|
  4382.   --| Notes (none)
  4383.  
  4384.   -- .......................................................
  4385.   -- .                                                     .
  4386.   -- .  LISTS.FORWARD                                      .  SPEC
  4387.   -- .                                                     .
  4388.   -- .......................................................
  4389.   procedure Forward (I :in out LISTITER);
  4390.   --| Purpose
  4391.   --| This procedure can be used in conjunction with Cell to iterate over a list.
  4392.   --| This is in addition to Next.  Instead of writing
  4393.   --|
  4394.   --|  I :ListIter;
  4395.   --|  L :List;
  4396.   --|  V :List_Element_Type;
  4397.   --|  
  4398.   --|  I := MakeListIter(L);
  4399.   --|  while More(I) loop
  4400.   --|      Next (I, V);
  4401.   --|      Print (V);
  4402.   --|  end loop;
  4403.   --| 
  4404.   --| One can write
  4405.   --|
  4406.   --| I := MakeListIter(L);
  4407.   --| while More (I) loop
  4408.   --|     Print (Cell (I));
  4409.   --|     Forward (I);
  4410.   --| end loop;
  4411.   --|
  4412.   --| Exceptions (none)
  4413.   --| Notes (none)
  4414.  
  4415.   -- .......................................................
  4416.   -- .                                                     .
  4417.   -- .  LISTS.ISEMPTY                                      .  SPEC
  4418.   -- .                                                     .
  4419.   -- .......................................................
  4420.   function IsEmpty (L: in LIST) return BOOLEAN;
  4421.   --| Purpose
  4422.   --| Return TRUE iff L is empty.
  4423.   --|
  4424.   --| Exceptions (none)
  4425.   --| Notes (none)
  4426.  
  4427.   -- .......................................................
  4428.   -- .                                                     .
  4429.   -- .  LISTS.ISINLIST                                     .  SPEC
  4430.   -- .                                                     .
  4431.   -- .......................................................
  4432.   function IsInList (L: in LIST; Element: in ITEMTYPE) return BOOLEAN;
  4433.   --| Purpose
  4434.   --| Walks down the list L looking for an element whose value is Element.
  4435.   --|
  4436.   --| Exceptions (none)
  4437.   --| Notes (none)
  4438.  
  4439.   -- .......................................................
  4440.   -- .                                                     .
  4441.   -- .  LISTS.LASTVALUE                                    .  SPEC
  4442.   -- .                                                     .
  4443.   -- .......................................................
  4444.   function LastValue (L: in LIST) return ITEMTYPE;
  4445.   --| Purpose
  4446.   --| Returns the last element in a list.  If the list is empty EmptyList is
  4447.   --| raised.
  4448.   --|
  4449.   --| Exceptions
  4450.   --|   EmptyList
  4451.   --|
  4452.   --| Notes (none)
  4453.  
  4454.   -- .......................................................
  4455.   -- .                                                     .
  4456.   -- .  LISTS.LENGTH                                       .  SPEC
  4457.   -- .                                                     .
  4458.   -- .......................................................
  4459.   function Length (L: in LIST) return INTEGER;
  4460.   --| Purpose
  4461.   --| Count the number of elements in list L.
  4462.   --|
  4463.   --| Exceptions (none)
  4464.   --| Notes (none)
  4465.  
  4466.   -- .......................................................
  4467.   -- .                                                     .
  4468.   -- .  LISTS.LENGTH                                       .  SPEC
  4469.   -- .                                                     .
  4470.   -- .......................................................
  4471.   function MakeList (E :in ITEMTYPE) return LIST;
  4472.   --| Purpose
  4473.   --| Takes in an element and returns a list.
  4474.   --|
  4475.   --| Exceptions (none)
  4476.   --| Notes (none)
  4477.  
  4478.   -- .......................................................
  4479.   -- .                                                     .
  4480.   -- .  LISTS.MAKELISTITER                                 .  SPEC
  4481.   -- .                                                     .
  4482.   -- .......................................................
  4483.   function MakeListIter (L: in LIST) return LISTITER;
  4484.   --| Purpose
  4485.   --| This prepares a user for iteration operation over a list.  The iterater is
  4486.   --| an operation which returns successive elements of the list on successive
  4487.   --| calls to the iterator.  There needs to be a mechanism which marks the
  4488.   --| position in the list, so on successive calls to the Next operation the
  4489.   --| next item in the list can be returned.  This is the function of the
  4490.   --| MakeListIter and the type ListIter.  MakeIter just sets the Iter to the
  4491.   --| the beginning  of the list. On subsequent calls to Next the Iter
  4492.   --| is updated with each call.
  4493.   --|
  4494.   --| Exceptions (none)
  4495.   --| Notes (none)
  4496.  
  4497.   -- .......................................................
  4498.   -- .                                                     .
  4499.   -- .  LISTS.MORE                                         .  SPEC
  4500.   -- .                                                     .
  4501.   -- .......................................................
  4502.   function More (L: in LISTITER) return BOOLEAN;
  4503.   --| Purpose
  4504.   --| Returns TRUE iff there are more elements in the list.
  4505.   --|
  4506.   --| Exceptions (none)
  4507.   --| Notes (none)
  4508.  
  4509.   -- .......................................................
  4510.   -- .                                                     .
  4511.   -- .  LISTS.NEXT                                         .  SPEC
  4512.   -- .                                                     .
  4513.   -- .......................................................
  4514.   procedure Next (Place: in out LISTITER; Info: out ITEMTYPE);
  4515.   --| Purpose
  4516.   --| This is the iterator operation.  Given a ListIter, Next returns the
  4517.   --| current item and updates the ListIter.
  4518.   --|
  4519.   --| The iterators subprograms MakeListIter, More, and Next should be used
  4520.   --| in the following way:
  4521.   --|
  4522.   --|         L:        List;
  4523.   --|         Place:    ListIter;
  4524.   --|         Info:     SomeType;
  4525.   --|
  4526.   --|     
  4527.   --|         Place := MakeListIter(L);
  4528.   --|
  4529.   --|         while ( More(Place) ) loop
  4530.   --|               Next(Place, Info);
  4531.   --|               process each element of list L;
  4532.   --|               end loop;
  4533.   --|
  4534.   --| Exceptions (none)
  4535.   --| Notes (none)
  4536.  
  4537.  
  4538.   -- .......................................................
  4539.   -- .                                                     .
  4540.   -- .  LISTS.REPLACEHEAD                                  .  SPEC
  4541.   -- .                                                     .
  4542.   -- .......................................................
  4543.   procedure ReplaceHead (L: in out LIST; Info: in ITEMTYPE);
  4544.   --| Purpose
  4545.   --| Replaces the information in the first element in the list.  Raises
  4546.   --| EmptyList if the list is empty.
  4547.   --|
  4548.   --| Exceptions
  4549.   --|   EmptyList
  4550.   --|
  4551.   --| Notes (none)
  4552.  
  4553.   -- .......................................................
  4554.   -- .                                                     .
  4555.   -- .  LISTS.REPLACETAIL                                  .  SPEC
  4556.   -- .                                                     .
  4557.   -- .......................................................
  4558.   procedure ReplaceTail (L: in out LIST; NewTail: in LIST);
  4559.   --| Purpose
  4560.   --| Replaces the tail of a list with a new list.  If the list whose tail
  4561.   --| is being replaced is null EmptyList is raised.
  4562.   --|
  4563.   --| Exceptions
  4564.   --|   EmptyList
  4565.   --|
  4566.   --| Notes (none)
  4567.  
  4568.   -- .......................................................
  4569.   -- .                                                     .
  4570.   -- .  LISTS.TAIL                                         .  SPEC
  4571.   -- .                                                     .
  4572.   -- .......................................................
  4573.   function Tail (L: in LIST) return LIST;
  4574.   --| Purpose
  4575.   --| Returns a list which is the tail of the list L.  Raises EmptyList if
  4576.   --| L is empty.  If L only has one element then Tail returns the Empty
  4577.   --| list.
  4578.   --|
  4579.   --| Exceptions
  4580.   --|   EmptyList
  4581.   --|
  4582.   --| Notes (none)
  4583.  
  4584.   -- .......................................................
  4585.   -- .                                                     .
  4586.   -- .  LISTS.CELLVALUE                                    .  SPEC
  4587.   -- .                                                     .
  4588.   -- .......................................................
  4589.   function CellValue (I :in LISTITER) return ITEMTYPE;
  4590.   --| Purpose
  4591.   --| This returns the value of the element at the position of the iterator.
  4592.   --| This is used in conjunction with Forward.
  4593.   --|
  4594.   --| Exceptions (none)
  4595.   --| Notes (none)
  4596.  
  4597.   -- .......................................................
  4598.   -- .                                                     .
  4599.   -- .  LISTS.EQUAL                                        .  SPEC
  4600.   -- .                                                     .
  4601.   -- .......................................................
  4602.   function Equal (List1: in LIST; List2: in LIST) return BOOLEAN;
  4603.   --| Purpose
  4604.   --| Returns true if for all elements of List1 the corresponding element
  4605.   --| of List2 has the same value.  This function uses the Equal operation
  4606.   --| provided by the user.  If one is not provided then = is used.
  4607.   --|
  4608.   --| Exceptions (none)
  4609.   --| Notes (none)
  4610.  
  4611. private
  4612.     type CELL;
  4613.     type LIST is access CELL;      -- pointer added by this package
  4614.                                    -- in order to make a list
  4615.     type CELL is                   -- Cell for the lists being created
  4616.          record
  4617.               Info : ITEMTYPE;
  4618.               Next : LIST;
  4619.          end record;
  4620.     type LISTITER is new LIST;     -- This prevents Lists being assigned to
  4621.                                    -- iterators and vice versa
  4622. end Lists;
  4623. --::::::::::
  4624. --logical.spc
  4625. --::::::::::
  4626. -- ***************************************************************
  4627. -- *                                                             *
  4628. -- *  LOGICAL                                                    *  SPEC
  4629. -- *                                                             *
  4630. -- ***************************************************************
  4631. package Logical is
  4632. --| Purpose
  4633. --| LOGICAL provides bit-level manipulation on INTEGER objects.
  4634. --|
  4635. --| Initialization Exceptions (none)
  4636. --| Notes
  4637. --|    Not all MIL-HDBK-1804 PDL annotations are
  4638. --| used in this package due to its simplicity.
  4639. --|    No exceptions are raised by this package.
  4640. --|
  4641. --| Modifications
  4642. --| Author: Joseph Orost, Concurrent Computer Corporation
  4643.  
  4644.   -- ..................................................................
  4645.   -- .                                                                .
  4646.   -- .  LOGICAL.ROTATE                                                .  SPEC
  4647.   -- .                                                                .
  4648.   -- ..................................................................
  4649.   function Rotate (Arg, Count : INTEGER) return INTEGER;
  4650.   --| Purpose
  4651.   --| Return arg rotated count bits.  
  4652.   --| If count < 0, rotate is to the right,
  4653.   --| else, rotate is to the left.
  4654.  
  4655.   -- ..................................................................
  4656.   -- .                                                                .
  4657.   -- .  LOGICAL.SHIFT                                                 .  SPEC
  4658.   -- .                                                                .
  4659.   -- ..................................................................
  4660.   function Shift (Arg, Count : INTEGER) return INTEGER;
  4661.   --| Purpose
  4662.   --| Return arg logically shifted count bits.
  4663.   --| Bits shifted out either end are lost.
  4664.   --| If count < 0, shift is to the right,
  4665.   --| else, shift is to the left
  4666.  
  4667.   -- ..................................................................
  4668.   -- .                                                                .
  4669.   -- .  LOGICAL."xor"                                                 .  SPEC
  4670.   -- .                                                                .
  4671.   -- ..................................................................
  4672.   function "xor" (Left, Right : INTEGER) return INTEGER;
  4673.   --| Purpose
  4674.   --| Return left XOR right.
  4675.  
  4676.   -- ..................................................................
  4677.   -- .                                                                .
  4678.   -- .  LOGICAL."and"                                                 .  SPEC
  4679.   -- .                                                                .
  4680.   -- ..................................................................
  4681.   function "and" (Left, Right : INTEGER) return INTEGER;
  4682.   --| Purpose
  4683.   --| Return left AND right.
  4684.  
  4685.   -- ..................................................................
  4686.   -- .                                                                .
  4687.   -- .  LOGICAL."or"                                                  .  SPEC
  4688.   -- .                                                                .
  4689.   -- ..................................................................
  4690.   function "or" (Left, Right : INTEGER) return INTEGER;
  4691.   --| Purpose
  4692.   --| Return left OR right.
  4693.  
  4694.   -- ..................................................................
  4695.   -- .                                                                .
  4696.   -- .  LOGICAL."not"                                                 .  SPEC
  4697.   -- .                                                                .
  4698.   -- ..................................................................
  4699.   function "not" (Right : INTEGER) return INTEGER;
  4700.   --| Purpose
  4701.   --| Return NOT right.
  4702.  
  4703. end Logical;
  4704. --::::::::::
  4705. --lparse.spc
  4706. --::::::::::
  4707. -- *****************************************************
  4708. -- *                                                   *
  4709. -- *  LINE_PARSER                                      *  SPEC
  4710. -- *                                                   *
  4711. -- *****************************************************
  4712. package Line_Parser is
  4713. --| Purpose
  4714. --| Line_Parser parses strings in a manner similar to ARGC/ARGV
  4715. --| under UNIX.  Function ARGC returns a count of the number of
  4716. --| tokens in the string and function ARGV returns each token
  4717. --| as a separate substring.
  4718. --|
  4719. --| Initialization Exceptions (none)
  4720. --| Notes (none)
  4721. --|
  4722. --| Modifications
  4723. --| Author:  Richard Conn
  4724.    
  4725.   -- .................................................
  4726.   -- .                                               .
  4727.   -- .  LINE_PARSER.INITIALIZE                       .  SPEC
  4728.   -- .                                               .
  4729.   -- .................................................
  4730.    procedure Initialize (Item : in STRING);
  4731.   --| Purpose
  4732.   --| Initialize this package.  This routine MUST be called
  4733.   --| before any other routines.
  4734.   --|
  4735.   --| Exceptions (none)
  4736.   --| Notes (none)
  4737.    
  4738.   -- ....................................................
  4739.   -- .                                                  .
  4740.   -- .  LINE_PARSER.ARGC                                .  SPEC
  4741.   -- .                                                  .
  4742.   -- ....................................................
  4743.    function ArgC return NATURAL;
  4744.   --| Purpose
  4745.   --| Return the number of tokens in the string.
  4746.   --|
  4747.   --| Exceptions (none)
  4748.   --| Notes (none)
  4749.    
  4750.   -- ...................................................
  4751.   -- .                                                 .
  4752.   -- .  LINE_PARSER.ARGV                               .  SPEC
  4753.   -- .                                                 .
  4754.   -- ...................................................
  4755.   function ArgV (Index : in NATURAL) return STRING;
  4756.   --| Purpose
  4757.   --| Return the Nth token in the string (the first token is
  4758.   --| numbered 0).  Valid values for INDEX are from 0 to
  4759.   --| ARGC-1.
  4760.   --|
  4761.   --| Exceptions
  4762.   --|   INVALID_INDEX is raised if INDEX > ARGC-1
  4763.   --|
  4764.   --| Notes (none)
  4765.    
  4766.    INVALID_INDEX    : exception;
  4767.    UNEXPECTED_ERROR : exception;
  4768.    
  4769. end Line_Parser;
  4770. --::::::::::
  4771. --matrix.spc
  4772. --::::::::::
  4773. -- ****************************************************************
  4774. -- *                                                              *
  4775. -- *  Matrix_Package                                              *  SPEC
  4776. -- *                                                              *
  4777. -- ****************************************************************
  4778. package MATRIX_PACKAGE is
  4779. --| Purpose
  4780. --| This package is a general purpose matrix package. It defines data
  4781. --| types VECTOR and MATRIX, and contains functions to perform general
  4782. --| matrix algebra operations.
  4783. --|
  4784. --| Initialization Exceptions (none)
  4785. --|
  4786. --| Notes
  4787. --|   Not all MIL-HDBK-1804 PDL annotations are used in this package
  4788. --| due to its simplicity.
  4789. --|
  4790. --| Modifications
  4791. --| Author: Dr. Roger Lee, Naval Air Development Center
  4792. --|         Art Adamson, Consultant
  4793.  
  4794. -- Types
  4795.   type VECTOR is array(integer range<>) of float ;
  4796.   subtype VEC2T is VECTOR (integer range 1..2) ;
  4797.   subtype VEC3T is VECTOR (integer range 1..3) ;
  4798.   type MATRIX is array(integer range<>,integer range <>) of float;
  4799.   type MATR2T is array(integer range<>) of VEC2T;
  4800.  
  4801. -- Exceptions
  4802.   INCOMPARABLE_DIMENSION :exception; -- the dimension of matrices
  4803.   -- or vectors to be operated are 
  4804.   -- incomparable
  4805.   SINGULAR : exception;    -- matrix to be inverted is singular
  4806.  
  4807. -- Operations
  4808.   function TRANSPOSE(A : MATRIX) return MATRIX ; -- transpose of matrix
  4809.   function TRANSPOSE(A : VECTOR) return VECTOR ; -- transpose of vector
  4810.   function "+" (A : VECTOR; B : VECTOR) return VECTOR ; -- sum of vector
  4811.   function "+" (A : MATRIX; B : MATRIX) return MATRIX ; -- sum of matrix
  4812.   function "+" (A : float;  B : VECTOR) return VECTOR ; 
  4813.   -- float added to, each term of matrix
  4814.   function "+" (A : VEC2T;  B : MATR2T) return MATR2T ;
  4815.   -- Vec2T added to, each term of MATR2T
  4816.   function "+" (A : MATR2T;  B : MATR2T) return MATR2T ;
  4817.   -- Corressponding terms added.
  4818.   function "-" (A : VECTOR; B : VECTOR) return VECTOR ; 
  4819.   -- difference of vector
  4820.   function "-" (A : MATRIX; B : MATRIX) return MATRIX ; 
  4821.   -- difference of matrix
  4822.   function "*" (A : float;  B : VECTOR) return VECTOR ; 
  4823.   -- scalar, vector multiplication
  4824.   function "*" (A : VECTOR; B : float)  return VECTOR ; 
  4825.   -- vector, scalar multiplication
  4826.   function "*" (A : VECTOR; B : VECTOR) return float ;  
  4827.   -- inner(dot) product of two vectors
  4828.   function "*" (A : MATRIX; B : VECTOR) return VECTOR ; 
  4829.   -- matrix,column vector multiplication
  4830.   function mat4mult(UL : MATRIX; UR : MATRIX; BL : MATRIX; BR : MATRIX;
  4831.                  B : VECTOR) return VECTOR ; 
  4832.   -- large matrix broken into 4 smaller ones, column vector multiplication 
  4833.   -- (upper left, upper right, bottom left, bottom right--all square)
  4834.   function "*" (A : VECTOR; B : MATRIX) return VECTOR ; 
  4835.   -- row vector,matrix multiplication
  4836.   function "*" (A : float;  B : MATRIX) return MATRIX ; 
  4837.   -- scalar, matrix multiplication
  4838.   function "*" (A : MATRIX; B : float)  return MATRIX ; 
  4839.   -- matrix, scalar multiplication
  4840.   function "*" (A : MATRIX; B : MATRIX) return MATRIX ; 
  4841.   -- matrix, matrix multiplication
  4842.   function "*" (A : float;  B : MATR2T) return MATR2T ;
  4843.   -- Multiplies each term of a MATR2T by a float
  4844.   function "*" (A : VEC2T;  B : MATR2T) return VECTOR ;
  4845.   -- Dot product of each term of MATR2T by a VEC2T, return array of floats
  4846.   function "*" (A : VECTOR;  B : MATR2T) return MATR2T ;
  4847.   --Multiplies each term of VEC2T by a corresponding float from a VECTOR
  4848.   function "**"(A : MATRIX; P : integer) return MATRIX; 
  4849.   -- square matrix raised to integer power
  4850.   -- if P = -1, we invert the matrix
  4851.   function "**" (A : VECTOR; B : VECTOR) return VECTOR ;
  4852.   -- A X B = ab sin(theta) a direction
  4853.   --perpendicular to plane of A & B.
  4854.   function JCROSS (A : VEC2T) return VEC2T ;
  4855.   --Rotates Vec2T 90 degrees CW.
  4856.   function JCROSS (A : MATR2T) return MATR2T ;
  4857.   --Rotates Vec2T's 90 degrees CW.
  4858.   function ROTX   (A : VEC2T) return VEC2T ;
  4859.   --Rotates Vec2T 180 degrees about the X axis.
  4860.   function ROTY   (A : VEC2T) return VEC2T ;
  4861.   --Rotates Vec2T 180 degrees about the Y axis.
  4862.   function aXbDOTj(A : VEC2T; B : VEC2T) return FLOAT;
  4863.   --Gets magnitude of A cross B for 2 2D vectors.
  4864.   function GETTAN (A : VEC2T; B : VEC2T) return FLOAT;
  4865.   --Gets TAN(THETA) between 2 2D vectors.
  4866.  
  4867. end MATRIX_PACKAGE;
  4868. --::::::::::
  4869. --mlib.spc
  4870. --::::::::::
  4871. -- ***************************************************************
  4872. -- *                                                             *
  4873. -- *  FLOATING_CHARACTERISTICS                                   *  SPEC
  4874. -- *                                                             *
  4875. -- ***************************************************************
  4876. package Floating_Characteristics is
  4877. --| Purpose
  4878. --| This package is a floating mantissa definition of a binary FLOAT 
  4879. --| It was first used on the DEC-10 and the VAX but should work for any
  4880. --| since the parameters are obtained by initializing on the actual hardware.
  4881. --| Otherwise the parameters could be set in the spec if known.
  4882. --| This is a preliminary package that defines the properties 
  4883. --| of the particular floating point type for which we are going to
  4884. --| generate the math routines.
  4885. --| The constants are those required by the routines described in
  4886. --| "Software Manual for the Elementary Functions" W. Cody & W. Waite
  4887. --| Prentice-Hall 1980.
  4888. --| Actually most are needed only for the test programs
  4889. --| rather than the functions themselves, but might as well be here.
  4890. --| Most of these could be in the form of attributes if 
  4891. --| all the floating types to be considered were those built into the
  4892. --| compiler, but we also want to be able to support user defined types
  4893. --| such as software floating types of greater precision than
  4894. --| the hardware affords, or types defined on one machine to
  4895. --| simulate another.
  4896. --| So we use the Cody-Waite names and derive them from an adaptation
  4897. --| of the MACHAR routine as given by Cody-Waite in Appendix B.
  4898. --|
  4899. --| Initialization Exceptions (none)
  4900. --|
  4901. --| Notes
  4902. --|    Not all MIL-HDBK-1804 PDL annotations are
  4903. --| used in this package due to its simplicity.
  4904. --|
  4905. --| Modifications
  4906. --| Author: Major Terry Courtwright, World Wide Military Command and
  4907. --|  Control Information Systems Joint Program Management Office
  4908.  
  4909.     Ibeta : INTEGER;
  4910.     --  The radix of the floating-point representation
  4911.  
  4912.     It : INTEGER;
  4913.     --  The number of base IBETA digits in the DIS_FLOAT significand
  4914.  
  4915.     Irnd : INTEGER;
  4916.     --  TRUE (1) if floating addition rounds, FALSE (0) if truncates
  4917.  
  4918.     Ngrd : INTEGER;
  4919.     --  Number of guard digits for multiplication
  4920.  
  4921.     Machep : INTEGER;
  4922.     --  The largest negative integer such that
  4923.     --    1.0 + FLOAT(IBETA) ** MACHEP /= 1.0
  4924.     --  except that MACHEP is bounded below by -(IT + 3)
  4925.  
  4926.     Negep : INTEGER;
  4927.     --  The largest negative integer such that
  4928.     --    1.0 -0 FLOAT(IBETA) ** NEGEP /= 1.0
  4929.     --  except that NEGEP is bounded below by -(IT + 3)
  4930.  
  4931.     Iexp : INTEGER;
  4932.     --  The number of bits (decimal places if IBETA = 10)
  4933.     --  reserved for the representation of the exponent (including
  4934.     --  the bias or sign) of a floating-point number
  4935.  
  4936.     Minexp : INTEGER;
  4937.     --  The largest in magnitude negative integer such that
  4938.     --  FLOAT(IBETA) ** MINEXP is a positive floating-point number
  4939.  
  4940.     Maxexp : INTEGER;
  4941.     --  The largest positive exponent for a finite floating-point number
  4942.  
  4943.     Eps : FLOAT;
  4944.     --  The smallest positive floating-point number such that
  4945.     --                              1.0 + EPS /= 1.0
  4946.     --  In particular, if IBETA = 2 or IRND = 0,
  4947.     --  EPS = FLOAT(IBETA) ** MACHEP
  4948.     --  Otherwise, EPS = (FLOAT(IBETA) ** MACHEP) / 2
  4949.  
  4950.     Epsneg : FLOAT;
  4951.     --  A small positive floating-point number such that 1.0-EPSNEG /= 1.0
  4952.  
  4953.     Xmin : FLOAT;
  4954.     --  The smallest non-vanishing floating-point power of the radix
  4955.     --  In particular, XMIN = FLOAT(IBETA) ** MINEXP
  4956.  
  4957.     Xmax : FLOAT;
  4958.     --  The largest finite floating-point number
  4959.  
  4960. --  Here the structure of the floating type is defined.
  4961. --  I have assumed that the exponent is always some integer form.
  4962. --  The mantissa can vary.
  4963. --  Most often it will be a fixed type or the same floating type
  4964. --  depending on the most efficient machine implementation.
  4965. --  Most efficient implementation may require details of the machine hardware
  4966. --  In this version the simplest representation is used.
  4967. --  The mantissa is extracted into a FLOAT and uses the predefined operations.
  4968.   subtype EXPONENT_TYPE is INTEGER;    --  should be derived
  4969.   subtype MANTISSA_TYPE is FLOAT;     --   range -1.0..1.0;
  4970.  
  4971. --  A consequence of the rigorous constraints on MANTISSA_TYPE is that 
  4972. --  operations must be very carefully examined to make sure that no number
  4973. --  greater than one results.
  4974. --  Actually this limitation is important in constructing algorithms
  4975. --  which will also run when MANTISSA_TYPE is a fixed point type.
  4976.  
  4977. --  If we are not using the STANDARD type, we have to define all the 
  4978. --  operations at this point.
  4979. --  We also need PUT for the type if it is not otherwise available.
  4980.  
  4981. --  Now we do something strange.
  4982. --  Since we do not know in the following routines whether the mantissa
  4983. --  will be carried as a fixed or floating type, we have to make some
  4984. --  provision for dividing by two.
  4985. --  We cannot use the literals, since FIXED/2.0 and FLOAT/2 will fail.
  4986. --  We define a type-dependent factor that will work.
  4987.   Mantissa_Divisor_2 : constant FLOAT := 2.0;
  4988.   Mantissa_Divisor_3 : constant FLOAT := 3.0;
  4989.  
  4990. --  This will work for the MANTISSA_TYPE defined above.
  4991. --  The alternative of defining an operation "/" to take care of it
  4992. --  is too sweeping and would allow unAda-like errors.
  4993.  
  4994.   Mantissa_Half : constant MANTISSA_TYPE := 0.5;
  4995.  
  4996. -- Subprograms
  4997.   procedure Defloat (X : in FLOAT;
  4998.                      L : out EXPONENT_TYPE;
  4999.                      E : out MANTISSA_TYPE);
  5000.   procedure Refloat (N : in EXPONENT_TYPE;
  5001.                      F : in MANTISSA_TYPE; 
  5002.                      Z : out FLOAT);
  5003.  
  5004. --  Since the user may wish to define a floating type by some other name
  5005. --  CONVERT_TO_FLOAT is used rather than just FLOAT for explicit coersion.
  5006.   function Convert_to_Float (K : INTEGER) return FLOAT;
  5007.  
  5008.   --function CONVERT_TO_FLOAT(N : EXPONENT_TYPE) return FLOAT;
  5009.   function Convert_to_Float (F : MANTISSA_TYPE) return FLOAT;
  5010.  
  5011. end Floating_Characteristics;
  5012.  
  5013. -- ***************************************************************
  5014. -- *                                                             *
  5015. -- *  NUMERIC_PRIMITIVES                                         *  SPEC
  5016. -- *                                                             *
  5017. -- ***************************************************************
  5018. with Floating_Characteristics;
  5019. use  Floating_Characteristics;
  5020. package Numeric_Primitives is
  5021. --| Purpose
  5022. --| This package contains the definitions of several useful constants
  5023. --| and functions associated with FLOAT numbers.
  5024. --|
  5025. --| Initialization Exceptions (none)
  5026. --|
  5027. --| Notes
  5028. --| Due to the simplicity of this package, the MIL-HDBK-1804 PDL
  5029. --| annotations are not used in the rest of this specification.
  5030. --|
  5031. --| Modifications
  5032. --| Author: Major Terry Courtwright, World Wide Military Command and
  5033. --|  Control Information Systems Joint Program Management Office
  5034.  
  5035.   --  This may seem a little much but is put in this form to allow the
  5036.   --  same form to be used for a generic package.
  5037.   --  If that is not needed, simple litterals could be substituted.
  5038.   Zero  : FLOAT;
  5039.   One   : FLOAT;
  5040.   Two   : FLOAT;
  5041.   Three : FLOAT;
  5042.   Half  : FLOAT;
  5043.  
  5044.   --  The following "constants" are effectively deferred to
  5045.   --  the initialization part of the package body.
  5046.   --  This is in order to make it possible to generalize the floating type.
  5047.   --  If that capability is not desired, constants may be included here.
  5048.   PI            : FLOAT;
  5049.   One_Over_PI   : FLOAT;
  5050.   Two_Over_PI   : FLOAT;
  5051.   PI_Over_Two   : FLOAT;
  5052.   PI_Over_Three : FLOAT;
  5053.   PI_Over_Four  : FLOAT;
  5054.   PI_Over_Six   : FLOAT;
  5055.  
  5056. -- Subprograms
  5057.   function Sign (X, Y : FLOAT) return FLOAT;
  5058.     --  Returns the value of X with the sign of Y.
  5059.  
  5060.   function Max (X, Y :  FLOAT) return FLOAT;
  5061.     --  Returns the algebraicly larger of X and Y.
  5062.  
  5063.   function Truncate (X : FLOAT) return FLOAT;
  5064.     --  Returns the floating value of the integer no larger than X.
  5065.     --  AINT(X)
  5066.  
  5067.   function Round (X : FLOAT) return FLOAT;
  5068.     --  Returns the floating value nearest X.
  5069.     --  AINTRND(X)
  5070.  
  5071.   function Ran return FLOAT;
  5072.     --  This uses a portable algorithm and is included at this point.
  5073.     --  Algorithms that presume unique machine hardware information
  5074.     --  should be initiated in FLOATING_CHARACTERISTICS.
  5075.  
  5076. end Numeric_Primitives;
  5077.  
  5078. -- ***************************************************************
  5079. -- *                                                             *
  5080. -- *  CORE_FUNCTIONS                                             *  SPEC
  5081. -- *                                                             *
  5082. -- ***************************************************************
  5083. with Floating_Characteristics;
  5084. use  Floating_Characteristics;
  5085. package Core_Functions is
  5086. --| Purpose
  5087. --| This package contains the definitions of several fundamental
  5088. --| functions associated with FLOAT numbers.
  5089. --|
  5090. --| Initialization Exceptions (none)
  5091. --|
  5092. --| Notes
  5093. --| Due to the simplicity of this package, the MIL-HDBK-1804 PDL
  5094. --| annotations are not used in the rest of this specification.
  5095. --|
  5096. --| Modifications
  5097. --| Author: Major Terry Courtwright, World Wide Military Command and
  5098. --|  Control Information Systems Joint Program Management Office
  5099.  
  5100.   Exp_Large : FLOAT;
  5101.   Exp_Small : FLOAT;
  5102.  
  5103. -- Subprograms
  5104.   function SQRT(X : FLOAT) return FLOAT;
  5105.  
  5106.   function CBRT(X : FLOAT) return FLOAT;
  5107.  
  5108.   function LOG(X : FLOAT) return FLOAT;
  5109.   function LOG10(X : FLOAT) return FLOAT;
  5110.  
  5111.   function EXP(X : FLOAT) return FLOAT;
  5112.  
  5113.   function "**"(X, Y : FLOAT) return FLOAT;
  5114.  
  5115. end Core_Functions;
  5116.  
  5117. -- ***************************************************************
  5118. -- *                                                             *
  5119. -- *  TRIG_FUNCTIONS                                             *  SPEC
  5120. -- *                                                             *
  5121. -- ***************************************************************
  5122. package Trig_Functions is
  5123. --| Purpose
  5124. --| This package contains the definitions of several trigonometric
  5125. --| and hypertrigonometic functions associated with FLOAT numbers.
  5126. --|
  5127. --| Initialization Exceptions (none)
  5128. --|
  5129. --| Notes
  5130. --| Due to the simplicity of this package, the MIL-HDBK-1804 PDL
  5131. --| annotations are not used in the rest of this specification.
  5132. --|
  5133. --| Modifications
  5134. --| Author: Major Terry Courtwright, World Wide Military Command and
  5135. --|  Control Information Systems Joint Program Management Office
  5136.  
  5137.   function SIN(X : FLOAT) return FLOAT;
  5138.   function COS(X : FLOAT) return FLOAT;
  5139.   function TAN(X : FLOAT) return FLOAT;
  5140.   function COT(X : FLOAT) return FLOAT;
  5141.  
  5142.   function ASIN(X : FLOAT) return FLOAT;
  5143.   function ACOS(X : FLOAT) return FLOAT;
  5144.   function ATAN(X : FLOAT) return FLOAT;
  5145.   function ATAN2(V, U : FLOAT) return FLOAT;
  5146.  
  5147.   function SINH(X : FLOAT) return FLOAT;
  5148.   function COSH(X : FLOAT) return FLOAT;
  5149.   function TANH(X : FLOAT) return FLOAT;
  5150.  
  5151. end Trig_Functions;
  5152. --::::::::::
  5153. --out.spc
  5154. --::::::::::
  5155. -- **********************************
  5156. -- *                                *
  5157. -- *  Output_File                   *  SPEC
  5158. -- *                                *
  5159. -- **********************************
  5160. package Output_File is
  5161. --| Purpose
  5162. --| Output_File implements an abstract data type of an output file.
  5163. --| Output_File offers an abstraction that can be made more efficient
  5164. --| by not using Text_IO (and having its associated overhead imposed)
  5165. --| if possible and also offers the ability to suppress the output,
  5166. --| which may be desired if a caller is skipping over pages and just
  5167. --| wants to output to a null device during this process.
  5168. --|
  5169. --| Initialization Exceptions (none)
  5170. --| Notes (none)
  5171. --|
  5172. --| Modifications
  5173. --| 08/16/89  Rick Conn    Initial Version
  5174.  
  5175.   type FILE_TYPE is
  5176.     private;
  5177.  
  5178.   Cannot_Create_Output_File
  5179.     : exception;
  5180.   Write_Error
  5181.     : exception;
  5182.  
  5183.   -- ..................................
  5184.   -- .                                .
  5185.   -- .  Output_File.Already_Exists    .  SPEC
  5186.   -- .                                .
  5187.   -- ..................................
  5188.   function Already_Exists
  5189.     ( File_Name      : in STRING )
  5190.     return BOOLEAN;
  5191.   --| Purpose
  5192.   --| Determine if the FILE_TYPE object already exists.
  5193.   --|
  5194.   --| Exceptions (none)
  5195.   --| Notes (none)
  5196.  
  5197.   -- ..................................
  5198.   -- .                                .
  5199.   -- .  Output_File.Delete            .  SPEC
  5200.   -- .                                .
  5201.   -- ..................................
  5202.   function Delete
  5203.     ( File_Name      : in STRING )
  5204.     return BOOLEAN;
  5205.   --| Purpose
  5206.   --| Delete the FILE_TYPE object.  Return TRUE if successful.
  5207.   --|
  5208.   --| Exceptions (none)
  5209.   --| Notes (none)
  5210.  
  5211.   -- ..................................
  5212.   -- .                                .
  5213.   -- .  Output_File.Create            .  SPEC
  5214.   -- .                                .
  5215.   -- ..................................
  5216.   procedure Create
  5217.     ( Id             : in out FILE_TYPE;
  5218.       File_Name      : in STRING );
  5219.   --| Purpose
  5220.   --| Create creates a new FILE_TYPE object.
  5221.   --|
  5222.   --| Exceptions
  5223.   --|   Cannot_Create_Output_File
  5224.   --|
  5225.   --| Notes (none)
  5226.  
  5227.   -- ..................................
  5228.   -- .                                .
  5229.   -- .  Output_File.Put               .  SPEC
  5230.   -- .                                .
  5231.   -- ..................................
  5232.   procedure Put
  5233.     ( Id             : in out FILE_TYPE;
  5234.       Item           : in CHARACTER );
  5235.   procedure Put
  5236.     ( Id             : in out FILE_TYPE;
  5237.       Item           : in STRING );
  5238.   --| Purpose
  5239.   --| Put writes an Item to the FILE_TYPE object.
  5240.   --|
  5241.   --| Exceptions
  5242.   --|   Write_Error
  5243.   --|
  5244.   --| Notes (none)
  5245.  
  5246.   -- ..................................
  5247.   -- .                                .
  5248.   -- .  Output_File.Put_Line          .  SPEC
  5249.   -- .                                .
  5250.   -- ..................................
  5251.   procedure Put_Line
  5252.     ( Id             : in out FILE_TYPE;
  5253.       Item           : in STRING );
  5254.   --| Purpose
  5255.   --| Put_Line writes an Item to the FILE_TYPE object.  The Item is followed
  5256.   --| by a New_Line;
  5257.   --|
  5258.   --| Exceptions
  5259.   --|   Write_Error
  5260.   --|
  5261.   --| Notes (none)
  5262.  
  5263.   -- ..................................
  5264.   -- .                                .
  5265.   -- .  Output_File.New_Line          .  SPEC
  5266.   -- .                                .
  5267.   -- ..................................
  5268.   procedure New_Line
  5269.     ( ID             : in out FILE_TYPE );
  5270.   --| Purpose
  5271.   --| New_Line writes an end-of-line sequence to the FILE_TYPE object.
  5272.   --|
  5273.   --| Exceptions
  5274.   --|   Write_Error
  5275.   --|
  5276.   --| Notes (none)
  5277.  
  5278.   -- ..................................
  5279.   -- .                                .
  5280.   -- .  Output_File.New_Page          .  SPEC
  5281.   -- .                                .
  5282.   -- ..................................
  5283.   procedure New_Page
  5284.     ( ID             : in out FILE_TYPE );
  5285.   --| Purpose
  5286.   --| New_Page writes an end-of-page sequence to the FILE_TYPE object.
  5287.   --|
  5288.   --| Exceptions
  5289.   --|   Write_Error
  5290.   --|
  5291.   --| Notes (none)
  5292.  
  5293.   -- ..................................
  5294.   -- .                                .
  5295.   -- .  Output_File.Enable_Output     .  SPEC
  5296.   -- .  Output_File.Disable_Output    .
  5297.   -- .                                .
  5298.   -- ..................................
  5299.   procedure Enable_Output
  5300.     ( ID             : in out FILE_TYPE );
  5301.   procedure Disable_Output
  5302.     ( ID             : in out FILE_TYPE );
  5303.   --| Purpose
  5304.   --| Enable_Output and Disable_Output enable and disable the output of
  5305.   --| Items and new lines to the FILE_TYPE object.  When created, output
  5306.   --| to a FILE_TYPE object is enabled.
  5307.   --|
  5308.   --| Exceptions (none)
  5309.   --| Notes (none)
  5310.  
  5311.   -- ..................................
  5312.   -- .                                .
  5313.   -- .  Output_File.Close             .  SPEC
  5314.   -- .                                .
  5315.   -- ..................................
  5316.   procedure Close
  5317.     ( ID             : in out FILE_TYPE );
  5318.   --| Purpose
  5319.   --| Close closes output to the FILE_TYPE object.
  5320.   --|
  5321.   --| Exceptions (none)
  5322.   --| Notes (none)
  5323.  
  5324. private -- Output_File
  5325.   type FILE_OBJECT;
  5326.   type FILE_TYPE is
  5327.     access FILE_OBJECT;
  5328.  
  5329. end Output_File;
  5330. --::::::::::
  5331. --permutat.spc
  5332. --::::::::::
  5333. -- ****************************************************
  5334. -- *                                                  *
  5335. -- *  Permutations_Class                              *  SPEC
  5336. -- *                                                  *
  5337. -- ****************************************************
  5338. generic
  5339.   type ITEM_TYPE  is private;
  5340.   type INDEX_TYPE is (<>);
  5341.   type LIST_TYPE  is array (INDEX_TYPE range <>) of ITEM_TYPE;
  5342. package Permutations_Class is
  5343. --| Purpose
  5344. --| Generate all permutations of a set of ITEM_TYPE objects.
  5345. --|
  5346. --| Initialization Exceptions (none)
  5347. --| Notes (none)
  5348. --|
  5349. --| Modifications
  5350. --| Author: Doug Bryan, Stanford University
  5351.  
  5352.   -- ........................................................
  5353.   -- .                                                      .
  5354.   -- .  Permutations_Class.Iterate_Through_Length...        .  SPEC
  5355.   -- .                                                      .
  5356.   -- ........................................................
  5357.   generic
  5358.     with procedure Process (A_Permutation : LIST_TYPE);
  5359.   procedure Iterate_Through_Length_Factorial_Permutations
  5360.     (Of_Items : LIST_TYPE);
  5361.   --| Purpose
  5362.   --| For an actual parameter for Of_Items of length n,
  5363.   --| n! (n factorial) permutations will be produced.
  5364.   --|
  5365.   --| The procedure permutes the elements in the array ITEMS.
  5366.   --| actually it permutes their indicies and re-arranges the items
  5367.   --| within the list.  The procedure does not care of any or all
  5368.   --| of the items in the list are equal (the same).
  5369.   --|
  5370.   --| Exceptions (none)
  5371.   --| Notes (none)
  5372.  
  5373. end Permutations_Class;
  5374. --::::::::::
  5375. --priqueue.spc
  5376. --::::::::::
  5377. -- ********************************************************
  5378. -- *                                                      *
  5379. -- *  PRIORITIZED_QUEUE                                   *  SPEC
  5380. -- *                                                      *
  5381. -- ********************************************************
  5382. generic
  5383.    type ENQUEUED_OBJECT is limited private;
  5384.    type PRIORITY_VALUE is (<>);
  5385.    with procedure Assign (Target : in out ENQUEUED_OBJECT;
  5386.                           Source : in     ENQUEUED_OBJECT) is <>;
  5387.    with function "=" (First_Object  : in ENQUEUED_OBJECT;
  5388.                       Second_Object : in ENQUEUED_OBJECT) return BOOLEAN is <>;
  5389.    with procedure Destroy (Targeted_Object : in out ENQUEUED_OBJECT) is <>;
  5390.    with function "<" (First_Object  : in PRIORITY_VALUE;
  5391.                       Second_Object : in PRIORITY_VALUE) return BOOLEAN is <>;
  5392. package Prioritized_Queue is
  5393. --| Purpose
  5394. --| Support prioritized queues.  Items may be added to removed
  5395. --| from these queues based on priority, as opposed to first
  5396. --| arrival.
  5397. --|
  5398. --| Initialization Exceptions (none)
  5399. --| Notes (none)
  5400. --|
  5401. --| Modifications
  5402. --| Author: Bill Wolfe, Clemson University
  5403.  
  5404. -- *******************************************************
  5405. -- This software is part of the Clemson University
  5406. -- Computer Science Department's Ada Software
  5407. -- Repository, and is copyrighted (C) 1989 by
  5408. -- Clemson University.  Permission to copy without
  5409. -- fee all or part of this software is granted,
  5410. -- provided that the copies are not made or
  5411. -- distributed for direct commercial advantage, and
  5412. -- that this copyright notice is not deleted or
  5413. -- modified.  To copy otherwise, or to republish,
  5414. -- requires a fee and/or specific permission.
  5415. -- *******************************************************
  5416.  
  5417.    type PRIORITY_QUEUE is limited private;
  5418.     -- requires O (n) space, where n is the NUMBER_OF_ITEMS in the queue.
  5419.  
  5420.    Requested_Item_Does_Not_Exist_In_This_Priority_Queue  : EXCEPTION;
  5421.    No_Items_Currently_Exist_In_This_Empty_Priority_Queue : EXCEPTION;
  5422.  
  5423.    type POINTER_TO_PRIORITY_QUEUE is access PRIORITY_QUEUE;
  5424.  
  5425.   -- ..........................................................
  5426.   -- .                                                        .
  5427.   -- .  PRIORITIZED_QUEUE.DESTROY                             .  SPEC
  5428.   -- .                                                        .
  5429.   -- ..........................................................
  5430.   procedure Destroy (Targeted_Object : in out POINTER_TO_PRIORITY_QUEUE);
  5431.   --| Purpose
  5432.   --| Remove the queue, freeing the space allocated to it.
  5433.   --|
  5434.   --| Exceptions (none)
  5435.   --|
  5436.   --| Notes
  5437.   --| Unlike UNCHECKED_DEALLOCATION, this procedure will properly
  5438.   --| destroy the PRIORITY_QUEUE being pointed to.  Works in O (n)
  5439.   --| time, where n is the NUMBER_OF_ITEMS in the PRIORITY_QUEUE
  5440.   --| being pointed to.
  5441.  
  5442.   -- ..........................................................
  5443.   -- .                                                        .
  5444.   -- .   PRIORITIZED_QUEUE.INSERT_ITEM                        .  SPEC
  5445.   -- .                                                        .
  5446.   -- ..........................................................
  5447.   procedure Insert_Item (Queue    : in out PRIORITY_QUEUE;
  5448.                          Object   : in     ENQUEUED_OBJECT;
  5449.                          Priority : in     PRIORITY_VALUE);
  5450.   --| Insert the indicated OBJECT into the QUEUE at the given PRIORITY.
  5451.   --|
  5452.   --| Exceptions (none)
  5453.   --|
  5454.   --| Notes
  5455.   --| The QUEUE can safely handle multiple instances of a given
  5456.   --| (OBJECT, PRIORITY) pair.  Works in O (log n) time, where n
  5457.   --| is the NUMBER_OF_ITEMS in the updated QUEUE.
  5458.   --| A series of consecutive initializing insertions uses O (n) time,
  5459.   --| where n is the number of insertions.
  5460.  
  5461.   -- ..........................................................
  5462.   -- .                                                        .
  5463.   -- .  PRIORITIZED_QUEUE.REMOVE_HIGHEST_PRIORITY_OBJECT      .  SPEC
  5464.   -- .                                                        .
  5465.   -- ..........................................................
  5466.   procedure Remove_Highest_Priority_Object
  5467.       (Highest_Priority_Object : in out ENQUEUED_OBJECT;
  5468.        Queue                   : in out PRIORITY_QUEUE); 
  5469.   --| Purpose
  5470.   --| Remove the highest priority object.  If there are several objects
  5471.   --| of the same highest priority, the first object entered will be
  5472.   --| removed.
  5473.   --|
  5474.   --| Exceptions
  5475.   --|   No_Items_Currently_Exist_In_This_Empty_Priority_Queue
  5476.   --|
  5477.   --| Notes
  5478.   --| Works in O (log n) time, where n is the NUMBER_OF_ITEMS
  5479.   --| originally in the QUEUE.  Raises
  5480.   --| No_Items_Currently_Exist_In_This_Empty_Priority_Queue
  5481.   --| if the QUEUE is EMPTY.
  5482.  
  5483.   -- ..........................................................
  5484.   -- .                                                        .
  5485.   -- .  PRIORITIZED_QUEUE.REMOVE_HIGHEST_PRIORITY_OBJECT      .  SPEC
  5486.   -- .                                                        .
  5487.   -- ..........................................................
  5488.   procedure Remove_Highest_Priority_Object
  5489.       (Highest_Priority_Object : in out ENQUEUED_OBJECT;
  5490.        Priority_of_the_Object  :    out PRIORITY_VALUE;
  5491.        Queue                   : in out PRIORITY_QUEUE); 
  5492.   --| Purpose
  5493.   --| Remove the highest priority object in a queue, returning both
  5494.   --| the object and its priority.
  5495.   --|
  5496.   --| Exceptions
  5497.   --|   No_Items_Currently_Exist_In_This_Empty_Priority_Queue
  5498.   --|
  5499.   --| Notes
  5500.   --| Works in O (log n) time, where n is the NUMBER_OF_ITEMS
  5501.   --| originally in the QUEUE.
  5502.   --| Raises No_Items_Currently_Exist_In_This_Empty_Priority_Queue
  5503.   --| if the QUEUE is EMPTY.
  5504.  
  5505.   -- ..........................................................
  5506.   -- .                                                        .
  5507.   -- .  PRIORITIZED_QUEUE.DELETE_ITEM                         .  SPEC
  5508.   -- .                                                        .
  5509.   -- ..........................................................
  5510.   procedure Delete_Item (Queue    : in out PRIORITY_QUEUE;
  5511.                          Object   : in     ENQUEUED_OBJECT;
  5512.                          Priority : in     PRIORITY_VALUE);
  5513.   --| Purpose
  5514.   --| Delete an item in the queue given the item and its priority.
  5515.   --|
  5516.   --| Exceptions
  5517.   --|   Requested_Item_Does_Not_Exist_In_This_Priority_Queue
  5518.   --|   No_Items_Currently_Exist_In_This_Empty_Priority_Queue
  5519.   --|
  5520.   --| Notes
  5521.   --| Works in O (n) time, where n is the NUMBER_OF_ITEMS originally
  5522.   --| in the QUEUE.
  5523.   --|
  5524.   --| If multiple occurrences of the specified OBJECT and PRIORITY
  5525.   --| exist, the first such occurrence found will be deleted, and
  5526.   --| all others will be left undisturbed.
  5527.   --|   PURGE_ITEM should be used if you wish to eliminate all such
  5528.   --| occurrences.
  5529.   --|
  5530.   --| If no occurrences of the specified OBJECT and PRIORITY exist,
  5531.   --| and the queue is not EMPTY, raises
  5532.   --| Requested_Item_Does_Not_Exist_In_This_Priority_Queue.
  5533.   --|
  5534.   --| If the QUEUE is EMPTY, raises
  5535.   --| No_Items_Currently_Exist_In_This_Empty_Priority_Queue.
  5536.  
  5537.   -- ..........................................................
  5538.   -- .                                                        .
  5539.   -- .  PRIORITIZED_QUEUE.PURGE_ITEM                          .  SPEC
  5540.   -- .                                                        .
  5541.   -- ..........................................................
  5542.   procedure Purge_Item (Queue  : in out PRIORITY_QUEUE;
  5543.                         Object : in     ENQUEUED_OBJECT);
  5544.   --| Purpose
  5545.   --| Remove all instances of an OBJECT regardless of its priority.
  5546.   --|
  5547.   --| Exceptions (none)
  5548.   --|
  5549.   --| Notes
  5550.   --| Works in O (n) time, where n is the NUMBER_OF_ITEMS originally
  5551.   --| in the QUEUE.
  5552.   --|
  5553.   --| Will terminate normally, even if the QUEUE was already EMPTY... 
  5554.  
  5555.   -- ..........................................................
  5556.   -- .                                                        .
  5557.   -- .  PRIORITIZED_QUEUE.PURGE_ITEM                          .  SPEC
  5558.   -- .                                                        .
  5559.   -- ..........................................................
  5560.   procedure Purge_Item (Queue    : in out PRIORITY_QUEUE;
  5561.                         Object   : in     ENQUEUED_OBJECT;
  5562.                         Priority : in     PRIORITY_VALUE);
  5563.   --| Purpose
  5564.   --| Remove all instances of an OBJECT at a given PRIORITY.
  5565.   --|
  5566.   --| Exceptions (none)
  5567.   --|
  5568.   --| Notes
  5569.   --| Works in O (n) time, where n is the NUMBER_OF_ITEMS originally
  5570.   --| in the QUEUE.
  5571.   --|
  5572.   --| Will terminate normally, even if the QUEUE was already EMPTY... 
  5573.  
  5574.   -- ..........................................................
  5575.   -- .                                                        .
  5576.   -- .  PRIORITIZED_QUEUE.PURGE_PRIORITY                      .  SPEC
  5577.   -- .                                                        .
  5578.   -- ..........................................................
  5579.   procedure Purge_Priority (Queue    : in out PRIORITY_QUEUE;
  5580.                             Priority : in     PRIORITY_VALUE);
  5581.   --| Purpose
  5582.   --| Removes all objects of a given PRIORITY.
  5583.   --|
  5584.   --| Exceptions (none)
  5585.   --|
  5586.   --| Notes
  5587.   --| Works in O (n) time, where n is the NUMBER_OF_ITEMS originally
  5588.   --| in the QUEUE.
  5589.   --|
  5590.   --| Will terminate normally, even if the QUEUE was already EMPTY... 
  5591.  
  5592.   -- ..........................................................
  5593.   -- .                                                        .
  5594.   -- .  PRIORITIZED_QUEUE.PURGE_PRIORITY_RANGE                .  SPEC
  5595.   -- .                                                        .
  5596.   -- ..........................................................
  5597.   procedure Purge_Priority_Range (Queue         : in out PRIORITY_QUEUE;
  5598.                                   From_Priority : in     PRIORITY_VALUE; 
  5599.                                   To_Priority   : in     PRIORITY_VALUE);
  5600.   --| Purpose
  5601.   --| Remove all objects with priorities between FROM_PRIORITY and
  5602.   --| TO_PRIORITY, inclusive.
  5603.   --|
  5604.   --| Exceptions (none)
  5605.   --|
  5606.   --| Notes
  5607.   --| Works in O (n) time, where n is the NUMBER_OF_ITEMS originally
  5608.   --| in the QUEUE.
  5609.   --|
  5610.   --| Will terminate normally, even if the QUEUE was already EMPTY... 
  5611.  
  5612.   -- ..........................................................
  5613.   -- .                                                        .
  5614.   -- .  PRIORITIZED_QUEUE.MERGE                               .  SPEC
  5615.   -- .                                                        .
  5616.   -- ..........................................................
  5617.   procedure Merge (Target_Queue : in out PRIORITY_QUEUE;
  5618.                    Source_Queue : in PRIORITY_QUEUE);
  5619.   --| Purpose
  5620.   --| Merge two queues.  The objects which were in the SOURCE_QUEUE
  5621.   --| are merged into the TARGET_QUEUE; the SOURCE_QUEUE
  5622.   --| is left EMPTY.
  5623.   --|
  5624.   --| Exceptions (none)
  5625.   --|
  5626.   --| Notes
  5627.   --| Works in O (log n) time, where n is the NUMBER_OF_ITEMS
  5628.   --| in the newly merged queue. 
  5629.  
  5630.   -- ..........................................................
  5631.   -- .                                                        .
  5632.   -- .  PRIORITIZED_QUEUE.CHANGE_PRIORITY                     .  SPEC
  5633.   -- .                                                        .
  5634.   -- ..........................................................
  5635.   procedure Change_Priority (Queue        : in out PRIORITY_QUEUE;
  5636.                              Object       : in     ENQUEUED_OBJECT;
  5637.                              Old_Priority : in     PRIORITY_VALUE;
  5638.                              New_Priority : in     PRIORITY_VALUE);
  5639.   --| Purpose
  5640.   --| Change the priority of an object in a queue.
  5641.   --|
  5642.   --| Exceptions
  5643.   --|   Requested_Item_Does_Not_Exist_In_This_Priority_Queue
  5644.   --|   No_Items_Currently_Exist_In_This_Empty_Priority_Queue
  5645.   --|
  5646.   --| Notes
  5647.   --| Works in O (n) time, where n is the NUMBER_OF_ITEMS in the QUEUE.
  5648.   --|
  5649.   --| If multiple occurrences of the specified OBJECT and OLD_PRIORITY
  5650.   --| exist in the QUEUE, the first such occurrence found will be
  5651.   --| modified, and all others will be left undisturbed.
  5652.   --|
  5653.   --| If no occurrences of the specified OBJECT and OLD_PRIORITY exist
  5654.   --| in the QUEUE, and the QUEUE is not EMPTY, raises
  5655.   --| Requested_Item_Does_Not_Exist_In_This_Priority_Queue.
  5656.   --|
  5657.   --| If the QUEUE is EMPTY, raises
  5658.   --| No_Items_Currently_Exist_In_This_Empty_Priority_Queue.
  5659.  
  5660.   -- ..........................................................
  5661.   -- .                                                        .
  5662.   -- .  PRIORITIZED_QUEUE.EMPTY                               .  SPEC
  5663.   -- .                                                        .
  5664.   -- ..........................................................
  5665.   function Empty (Queue : in PRIORITY_QUEUE) return BOOLEAN;
  5666.   --| Purpose
  5667.   --| Determine if a queue is empty.
  5668.   --|
  5669.   --| Exceptions (none)
  5670.   --|
  5671.   --| Notes
  5672.   --| Works in O (1) time.
  5673.  
  5674.   -- ..........................................................
  5675.   -- .                                                        .
  5676.   -- .  PRIORITIZED_QUEUE.NUMBER_OF_ITEMS                     .  SPEC
  5677.   -- .                                                        .
  5678.   -- ..........................................................
  5679.   function Number_of_Items (Queue : in PRIORITY_QUEUE)
  5680.       return NATURAL;
  5681.   --| Purpose
  5682.   --| Determines the number of items in a queue.
  5683.   --|
  5684.   --| Exceptions (none)
  5685.   --|
  5686.   --| Notes
  5687.   --| Works in O (n) time, where n is the NUMBER_OF_ITEMS in the QUEUE.
  5688.  
  5689.   -- ..........................................................
  5690.   -- .                                                        .
  5691.   -- .  PRIORITIZED_QUEUE.ASSIGN                              .  SPEC
  5692.   -- .                                                        .
  5693.   -- ..........................................................
  5694.   procedure Assign (Target_Object : in out PRIORITY_QUEUE;
  5695.                     Source_Object : in     PRIORITY_QUEUE);
  5696.   --| Purpose
  5697.   --| Assign one queue to another, replacing the TARGET_OBJECT.
  5698.   --|
  5699.   --| Exceptions (none)
  5700.   --|
  5701.   --| Notes
  5702.   --| Works in O (n) time, where n is the maximum of the
  5703.   --| NUMBER_OF_ITEMS to be destroyed in the TARGET_OBJECT
  5704.   --| and the NUMBER_OF_ITEMS in the SOURCE_OBJECT.
  5705.  
  5706.   -- ..........................................................
  5707.   -- .                                                        .
  5708.   -- .  PRIORITIZED_QUEUE.DESTROY                             .  SPEC
  5709.   -- .                                                        .
  5710.   -- ..........................................................
  5711.   procedure Destroy (Targeted_Object : in out PRIORITY_QUEUE);
  5712.   --| Purpose
  5713.   --| Destroy a queue, freeing its contents.
  5714.   --|
  5715.   --| Exceptions (none)
  5716.   --|
  5717.   --| Notes
  5718.   --| Works in O (n) time, where n is the NUMBER_OF_ITEMS in the QUEUE.
  5719.  
  5720. private
  5721.   type PRIORITY_QUEUE_NODE;
  5722.   type PRIORITY_QUEUE is access PRIORITY_QUEUE_NODE;   
  5723.  
  5724. end PRIORITIZED_QUEUE;
  5725. --::::::::::
  5726. --qsort.spc
  5727. --::::::::::
  5728. -- ....................................................
  5729. -- .                                                  .
  5730. -- .  QSORT                                           .  SPEC
  5731. -- .                                                  .
  5732. -- ....................................................
  5733. generic
  5734.   type ITEM is private;
  5735.   type INDEX is (<>);
  5736.   type ROW is array (INDEX range <>) of ITEM;
  5737.   with function "<" (X, Y : ITEM) return BOOLEAN is <>;
  5738. procedure Qsort (A : in out ROW);
  5739. --| Purpose
  5740. --| Sort the one-dimensional array A using the Quick Sort
  5741. --| algorithm.
  5742. --|
  5743. --| Exceptions (none)
  5744. --| Notes (none)
  5745. --|
  5746. --| Modifications
  5747. --| Author: John Anderson, TI
  5748. --::::::::::
  5749. --random.spc
  5750. --::::::::::
  5751. -- ********************************************************
  5752. -- *                                                      *
  5753. -- *  RANDOM                                              *  SPEC
  5754. -- *                                                      *
  5755. -- ********************************************************
  5756. package Random is
  5757. --| Purpose
  5758. --| Random.Number returns a pseudo-random number in 0.0 .. 1.0.
  5759. --|
  5760. --| Initialization Exceptions (none)
  5761. --| Notes
  5762. --|    Uses 16-bit integers, so should be quite portable.
  5763. --|    Not all MIL-HDBK-1804 PDL annotations are
  5764. --| used in this package due to its simplicity.
  5765. --|
  5766. --| Modifications
  5767. --|     Original Work: Bill Whitaker
  5768. --|     Later Mods by: Richard Conn, Ron Bell
  5769.  
  5770.   -- ......................................................
  5771.   -- .                                                    .
  5772.   -- .  RANDOM.NUMBER                                     .  SPEC
  5773.   -- .                                                    .
  5774.   -- ......................................................
  5775.   function Number return FLOAT;
  5776.  
  5777. end Random;
  5778. --::::::::::
  5779. --scanners.spc
  5780. --::::::::::
  5781. -- **************************************************
  5782. -- *                                                *
  5783. -- *  Scanners                                      *  SPEC
  5784. -- *                                                *
  5785. -- **************************************************
  5786. package Scanners is
  5787. --| Purpose
  5788. --| This package is used to break strings into tokens in a
  5789. --| very simple but efficient manner.  For maximum efficiency,
  5790. --| the scanner type is not private so that it can be used
  5791. --| directly.  The following conventions are adopted to allow
  5792. --| the Ada string handling primitives to be used to maximum
  5793. --| advantage:
  5794. --|
  5795. --|  1. Strings are never copied.  The scanner type contains
  5796. --|     First and Last components so that slices may be used
  5797. --|     to obtain the desired tokens (substrings).
  5798. --| 
  5799. --|  2. The scanner type does not include a copy of the
  5800. --|     string being scanned, also to avoid copying strings.
  5801. --| 
  5802. --|  3. The Length component of a scanner is always set to the
  5803. --|     length of the item scanned.  If it is zero it means
  5804. --|     that no such item was found, either because it wasn't
  5805. --|     there or because the scanner is exhausted. The is_Empty
  5806. --|     operation may be used to determint if a scanner is
  5807. --|     exhausted (usually before attempting to scan something).
  5808. --|
  5809. --|  4. All operations have well defined behavior for any
  5810. --|     consistent input. There are no exceptions declared in
  5811. --|     this package or raised directly by the operations in
  5812. --|     the package.
  5813. --|
  5814. --| Initialization Exceptions (none)
  5815. --|
  5816. --| Notes
  5817. --|    Not all MIL-HDBK-1804 PDL annotations are
  5818. --| used in this package due to its simplicity.
  5819. --|    No exceptions are raised by this package.
  5820. --|
  5821. --| Modifications
  5822. --| Author: Bill Toscano and Michael Gordon, Intermetrics
  5823.  
  5824. -- Types:
  5825.   type SCANNER_TYPE is record
  5826.     Index     : NATURAL;  -- Index of next char to be scanned
  5827.     Max_Index : NATURAL;  -- Index of last scannable char
  5828.     First     : NATURAL;  -- Index of 1st char of the result of a scan
  5829.     Last      : NATURAL;  -- Index of last char of the result of a scan
  5830.     Length    : NATURAL;  -- Length of the item scanned
  5831.   end record;
  5832.  
  5833. -- Constructors:
  5834.  
  5835.   -- ...............................................
  5836.   -- .                                             .
  5837.   -- .  Scanners.Start_Scanner                     .  SPEC
  5838.   -- .                                             .
  5839.   -- ...............................................
  5840.   procedure Start_Scanner (
  5841.     Scanner : in out SCANNER_TYPE;
  5842.     S       : in STRING;
  5843.     Last    : in NATURAL);
  5844.   --| Purpose
  5845.   --| Initialize Scanner for scanning S from S'FIRST to Last.
  5846.   --| S and Last are typically obtained by calling
  5847.   --| Text_IO.Get_Line.
  5848.  
  5849.   -- ...............................................
  5850.   -- .                                             .
  5851.   -- .  Scanners.Is_Empty                          .  SPEC
  5852.   -- .                                             .
  5853.   -- ...............................................
  5854.   function Is_Empty (Scanner: in SCANNER_TYPE)
  5855.     return BOOLEAN;
  5856.   pragma inline(is_Empty);
  5857.   --| Purpose
  5858.   --| Return True iff Scanner.Index > Scanner.Max_Index.
  5859.   --| Return TRUE iff there are more characters to scan.
  5860.  
  5861.   -- ...............................................
  5862.   -- .                                             .
  5863.   -- .  Scanners.Is_Alpha                          .  SPEC
  5864.   -- .                                             .
  5865.   -- ...............................................
  5866.   function Is_Alpha (Scanner : in SCANNER_TYPE;
  5867.                      S       : in STRING)
  5868.     return BOOLEAN;
  5869.   pragma inline(is_Alpha);
  5870.   --| Purpose
  5871.   --| Return True iff S(Scanner.Index) is an alphabetic character.
  5872.  
  5873.   -- ...............................................
  5874.   -- .                                             .
  5875.   -- .  Scanners.Is_Alpha                          .  SPEC
  5876.   -- .                                             .
  5877.   -- ...............................................
  5878.   function Is_Digit (Scanner : in SCANNER_TYPE;
  5879.                      S       : in string)
  5880.     return BOOLEAN;
  5881.   pragma inline(is_Digit);
  5882.   --| Purpose
  5883.   --| Return True iff S(Scanner.Index) is a decimal digit.
  5884.  
  5885.   -- ...............................................
  5886.   -- .                                             .
  5887.   -- .  Scanners.Is_Sign                           .  SPEC
  5888.   -- .                                             .
  5889.   -- ...............................................
  5890.   function Is_Sign (Scanner : in SCANNER_TYPE;
  5891.                     S       : in STRING)
  5892.     return BOOLEAN;
  5893.   pragma inline(is_Sign);
  5894.   --| Purpose
  5895.   --| Return True iff S(Scanner.Index) is '+' or '-'
  5896.  
  5897.   -- ...............................................
  5898.   -- .                                             .
  5899.   -- .  Scanners.Is_Digit_or_Sign                  .  SPEC
  5900.   -- .                                             .
  5901.   -- ...............................................
  5902.   function Is_Digit_or_Sign (Scanner : in SCANNER_TYPE;
  5903.                              S       : in string)
  5904.     return BOOLEAN;
  5905.   pragma inline(is_Digit_or_Sign);
  5906.   --| Purpose
  5907.   --| Return True iff S(Scanner.Index) is '+', '-', or a decimal digit.
  5908.  
  5909.   -- ...............................................
  5910.   -- .                                             .
  5911.   -- .  Scanners.Skip_Blanks                       .  SPEC
  5912.   -- .                                             .
  5913.   -- ...............................................
  5914.   procedure Skip_Blanks (Scanner : in out SCANNER_TYPE;
  5915.                          S       : in STRING);
  5916.   --| Purpose
  5917.   --| Increment Scanner.Index until S(Scanner.Index) is
  5918.   --| neither a blank nor a tab character, or until it is
  5919.   --| greater than Scanner.Max_Index.
  5920.  
  5921.   -- ...............................................
  5922.   -- .                                             .
  5923.   -- .  Scanners.Trim_Blanks                       .  SPEC
  5924.   -- .                                             .
  5925.   -- ...............................................
  5926.   procedure Trim_Blanks (Scanner : in out SCANNER_TYPE;
  5927.                          S       : in STRING);
  5928.   --| Purpose
  5929.   --| Adjust Scanner.First and Scanner.Last such that 
  5930.   --| S(Scanner.First..Scanner.Last) contains neither leading
  5931.   --| nor trailing blanks or tabs.  Scanner.Length is adjusted
  5932.   --| accordingly.  This is useful to remove blanks after a
  5933.   --| call to Scan_Delimited, Scan_Quoted, Scan_Until, etc.
  5934.  
  5935.   -- ...............................................
  5936.   -- .                                             .
  5937.   -- .  Scanners.Scan_Until                        .  SPEC
  5938.   -- .                                             .
  5939.   -- ...............................................
  5940.   procedure Scan_Until (Scanner : in out SCANNER_TYPE;
  5941.                         S       : in STRING;
  5942.                         C       : in CHARACTER);
  5943.   --| Purpose
  5944.   --| Scan in string S starting at Scanner.Index until the
  5945.   --| character C is encountered or the string ends.  On
  5946.   --| return, if Scanner.Length > 0 then
  5947.   --| S(Scanner.First..Scanner.Last) contains the characters that
  5948.   --| appeared before C and Scanner(Index) = C.  If C was
  5949.   --| not found, then the scanner is not affected except to
  5950.   --| set Scanner.Length to 0.
  5951.  
  5952.   -- ...............................................
  5953.   -- .                                             .
  5954.   -- .  Scanners.Scan_Word                         .  SPEC
  5955.   -- .                                             .
  5956.   -- ...............................................
  5957.   procedure Scan_Word (Scanner : in out SCANNER_TYPE;
  5958.                        S       : in STRING);
  5959.   --| Purpose
  5960.   --| Scan in string S for a sequence of non-blank characters,
  5961.   --| starting at Scanner.Index.  On return, if
  5962.   --| Scanner.Length > 0 then S(Scanner.First..Scanner.Last)
  5963.   --| is a word and Scanner.Index is just past the end of the
  5964.   --| word (Scanner.Last+1), ready to scan the next item.  
  5965.  
  5966.   -- ...............................................
  5967.   -- .                                             .
  5968.   -- .  Scanners.Scan_Number                       .  SPEC
  5969.   -- .                                             .
  5970.   -- ...............................................
  5971.   procedure Scan_Number (Scanner : in out SCANNER_TYPE;
  5972.                          S       : in STRING);
  5973.   --| Purpose
  5974.   --| Scan in string S for a sequence of numeric characters,
  5975.   --| optionally preceeded by a sign (+/-), starting at
  5976.   --| Scanner.Index.  On return, if Scanner.Length > 0 then
  5977.   --| S(Scanner.First..Scanner.Last) is a number and
  5978.   --| Scanner.Index is just past the end of the number
  5979.   --| (Scanner.Last+1), ready to scan the next item.
  5980.  
  5981.   -- ...............................................
  5982.   -- .                                             .
  5983.   -- .  Scanners.Scan_Delimited                    .  SPEC
  5984.   -- .                                             .
  5985.   -- ...............................................
  5986.   procedure Scan_Delimited (Scanner : in out SCANNER_TYPE;
  5987.                             S       : in STRING);
  5988.   --| Purpose
  5989.   --| The character S(Scanner.Index) is considered a "quote".  
  5990.   --| Scanner.First is set to the Scanner.Index+1, and
  5991.   --| Scanner.Index is incremented until another "quote"
  5992.   --| is encountered or the end of the string is reached.
  5993.   --| On return, Scanner.Last is the index of the closing
  5994.   --| "quote" or the last character in S if no closing "quote"
  5995.   --| was found.
  5996.  
  5997.   -- ...............................................
  5998.   -- .                                             .
  5999.   -- .  Scanners.Scan_Quoted                       .  SPEC
  6000.   -- .                                             .
  6001.   -- ...............................................
  6002.   procedure Scan_Quoted (Scanner : in out SCANNER_TYPE;
  6003.                          S       : in out STRING);
  6004.   --| Purpose
  6005.   --| The character S(Scanner.Index) is considered a "quote".  
  6006.   --| The string S is scanned for a closing "quote".  During
  6007.   --| the scan, two quotes in a row are replaced by a single
  6008.   --| quote.  On return, Scanner.First is the first character
  6009.   --| of the quoted string, and Scanner.Last is the last
  6010.   --| character.  (The outermost quotes are not included.)
  6011.   --| Scanner.Index is the first character after the
  6012.   --| closing quote, Scanner.Length is the number of characters
  6013.   --| in the quoted string.  Note that the string being scanned
  6014.   --| (S) is modified by this routine (to remove the extra quotes,
  6015.   --| if any).
  6016.  
  6017. end Scanners;
  6018. --::::::::::
  6019. --search.spc
  6020. --::::::::::
  6021. -- *****************************************************
  6022. -- *                                                   *
  6023. -- *  SEARCH_UTILITIES                                 *  SPEC
  6024. -- *                                                   *
  6025. -- *****************************************************
  6026. with System;
  6027. generic
  6028.   type COMPONENT_TYPE is limited private;  -- type of component to search for
  6029.   type INDEX_TYPE     is (<>);             -- type of array index
  6030.   type ARRAY_TYPE is array (INDEX_TYPE range <>) of COMPONENT_TYPE;
  6031.   with function "<"(Left, Right : in COMPONENT_TYPE) return BOOLEAN is <>;
  6032.   with function "="(Left, Right : in COMPONENT_TYPE) return BOOLEAN is <>;
  6033. package Search_Utilities is
  6034. --| Purpose
  6035. --| Search_Utilities is a generic searching package. The Search subprograms
  6036. --| will search a one dimensional array of any data type
  6037. --| indexed by discrete type components.
  6038. --|
  6039. --| Note that the component type of the array is not restricted to simple
  6040. --| types. An array of records or allocators can be searched. If the
  6041. --| component type is a record or allocator, then the generic formal
  6042. --| subprogram parameter "<" below must be specified as a selector
  6043. --| function.
  6044. --|
  6045. --| Initialization Exceptions (none)
  6046. --| Notes (none)
  6047. --|
  6048. --| Modifications
  6049. --| Author: Geoff Mendal, Stanford University
  6050.  
  6051.   type DATA_ORDER_TYPE is (ORDERED, NOT_ORDERED);
  6052.   -- This type should be used to specify how the data is
  6053.   -- ordered.  The default is Not_Ordered.  However, significant CPU time
  6054.   -- can be saved if the data is ordered and the default, Not_Ordered,
  6055.   -- is overridden.
  6056.   --
  6057.   -- If the data are ordered, then if two or more components in the array
  6058.   -- can match the search component provided, then the component location
  6059.   -- returned by Search should be thought of as an arbitrary selection
  6060.   -- from amongst those possible match-components.
  6061.   --
  6062.   -- If the data are not ordered, then if two or more components in the
  6063.   -- array can match the search component provided, then the component
  6064.   -- location returned by Search will be the one closest to
  6065.   -- Search_Array'FIRST.
  6066.  
  6067.   type PERFORMANCE_INSTRUMENTATION_TYPE is range -1 .. System.Max_Int;
  6068.   -- This type declaration should be used to specify the
  6069.   -- instrumentation analysis data that can be returned by the
  6070.   -- Search procedure below.  -1 is only returned if an overflow in
  6071.   -- calculations has occurred.  The Search subprograms will not terminate
  6072.   -- if an overflow in instrumentation analysis data calculations has
  6073.   -- occurred.
  6074.  
  6075.   -- ....................................................
  6076.   -- .                                                  .
  6077.   -- .  SEARCH_UTILITIES.VERSION                        .  SPEC
  6078.   -- .                                                  .
  6079.   -- ....................................................
  6080.   function Version return STRING;
  6081.   --| Purpose
  6082.   --| Returns the version number of this package.
  6083.   --|
  6084.   --| Exceptions (none)
  6085.   --| Notes (none)
  6086.  
  6087.   -- ....................................................
  6088.   -- .                                                  .
  6089.   -- .  SEARCH_UTILITIES.SEARCH                         .  SPEC
  6090.   -- .                                                  .
  6091.   -- ....................................................
  6092.   procedure Search (
  6093.     Component                        : in     COMPONENT_TYPE;
  6094.     Search_Array                     : in     ARRAY_TYPE;
  6095.     Location_Found                   :    out INDEX_TYPE;
  6096.     Component_Found                  :    out BOOLEAN;
  6097.     Number_of_Comparisons            :    out PERFORMANCE_INSTRUMENTATION_TYPE;
  6098.     Order_Strategy                   : in     DATA_ORDER_TYPE := NOT_ORDERED;
  6099.     No_Match_Index                   : in     INDEX_TYPE      := INDEX_TYPE'LAST);
  6100.   --| Purpose
  6101.   --| This procedure will search a one dimensional array of
  6102.   --| components.  It can search an ordered or unordered array.  If
  6103.   --| an ordered array is specified, it defaults to an ascending
  6104.   --| order (which can be overridden by the user).  The array components
  6105.   --| must only support equality, inequality, and assignment (private
  6106.   --| types).  The array indices can be of any discrete type.  The number
  6107.   --| of comparisons can also be returned.
  6108.   --|
  6109.   --| Exceptions (none)
  6110.   --| Notes (none)
  6111.  
  6112.   -- ....................................................
  6113.   -- .                                                  .
  6114.   -- .  SEARCH_UTILITIES.SEARCH                         .  SPEC
  6115.   -- .                                                  .
  6116.   -- ....................................................
  6117.   procedure Search (
  6118.     Component                        : in     COMPONENT_TYPE;
  6119.     Search_Array                     : in     ARRAY_TYPE;
  6120.     Location_Found                   :    out INDEX_TYPE;
  6121.     Component_Found                  :    out BOOLEAN;
  6122.     Order_Strategy                   : in     DATA_ORDER_TYPE := NOT_ORDERED;
  6123.     No_Match_Index                   : in     INDEX_TYPE := INDEX_TYPE'LAST);
  6124.   --| Purpose
  6125.   --| This overloading of procedure Search should be used when
  6126.   --| no instrumentation analysis data are required.
  6127.   --|
  6128.   --| Exceptions (none)
  6129.   --| Notes (none)
  6130.  
  6131.   -- ....................................................
  6132.   -- .                                                  .
  6133.   -- .  SEARCH_UTILITIES.SEARCH                         .  SPEC
  6134.   -- .                                                  .
  6135.   -- ....................................................
  6136.   function Search (
  6137.     Component                        : in COMPONENT_TYPE;
  6138.     Search_Array                     : in ARRAY_TYPE;
  6139.     Order_Strategy                   : in DATA_ORDER_TYPE := NOT_ORDERED)
  6140.     return BOOLEAN;
  6141.   --| Purpose
  6142.   --| This overloading of function Search should be used when
  6143.   --| the user only wants to know if the component exists or not.
  6144.   --|
  6145.   --| Exceptions (none)
  6146.   --| Notes (none)
  6147.  
  6148.   -- ....................................................
  6149.   -- .                                                  .
  6150.   -- .  SEARCH_UTILITIES.SEARCH                         .  SPEC
  6151.   -- .                                                  .
  6152.   -- ....................................................
  6153.   function Search (
  6154.     Component                        : in COMPONENT_TYPE;
  6155.     Search_Array                     : in ARRAY_TYPE;
  6156.     Order_Strategy                   : in DATA_ORDER_TYPE := NOT_ORDERED;
  6157.     No_Match_Index                   : in INDEX_TYPE      := INDEX_TYPE'LAST)
  6158.     return INDEX_TYPE;
  6159.   --| Purpose
  6160.   --| This overloading of function Search should be used when
  6161.   --| the component is definitely known to exist and only the location
  6162.   --| is required.  (Note that No_Match_Index may be used to return a
  6163.   --| no match index value... but this won't work in all cases.)
  6164.   --|
  6165.   --| Exceptions (none)
  6166.   --| Notes (none)
  6167.  
  6168. end Search_Utilities;
  6169. --::::::::::
  6170. --slist.spc
  6171. --::::::::::
  6172. -- *****************************************************************
  6173. -- *                                                               *
  6174. -- *  SINGLY_LINKED_LIST                                           *  SPEC
  6175. -- *                                                               *
  6176. -- *****************************************************************
  6177. generic
  6178.   type LIST_ELEMENT is private;
  6179. package Singly_Linked_List is
  6180. --| Purpose
  6181. --| This package provides an abstraction for a singly linked list.
  6182. --|
  6183. --| Initialization Exceptions (none)
  6184. --| Notes (none)
  6185. --|
  6186. --| Modifications
  6187. --| Author: Richard Conn
  6188.  
  6189. -- Types
  6190.   type LIST_TYPE is limited private;
  6191.  
  6192. -- Exceptions
  6193.   End_Error : exception;
  6194.  
  6195.   -- .............................................................
  6196.   -- .                                                           .
  6197.   -- .  SINGLY_LINKED_LIST.EMPTY                                 .  SPEC
  6198.   -- .                                                           .
  6199.   -- .............................................................
  6200.   function Empty (List : LIST_TYPE) return BOOLEAN;
  6201.   --| Purpose
  6202.   --| Indicates whether the list contains any elements.
  6203.   --|
  6204.   --| Exceptions (none)
  6205.   --| Notes (none)
  6206.  
  6207.   -- .............................................................
  6208.   -- .                                                           .
  6209.   -- .  SINGLY_LINKED_LIST.NULL_NODE                             .  SPEC
  6210.   -- .                                                           .
  6211.   -- .............................................................
  6212.   function Null_Node (List : LIST_TYPE) return BOOLEAN;
  6213.   --| Purpose
  6214.   --| Indicates whether the "current pointer" references an element
  6215.   --| in the list.
  6216.   --|
  6217.   --| Exceptions (none)
  6218.   --| Notes (none)
  6219.  
  6220.   -- .............................................................
  6221.   -- .                                                           .
  6222.   -- .  SINGLY_LINKED_LIST.HEAD_NODE                             .  SPEC
  6223.   -- .                                                           .
  6224.   -- .............................................................
  6225.   function Head_Node (List : LIST_TYPE) return BOOLEAN;
  6226.   --| Purpose
  6227.   --| Indicates whether the "current pointer" references the head
  6228.   --| of the list.
  6229.   --|
  6230.   --| Exceptions (none)
  6231.   --| Notes (none)
  6232.  
  6233.   -- .............................................................
  6234.   -- .                                                           .
  6235.   -- .  SINGLY_LINKED_LIST.TAIL_NODE                             .  SPEC
  6236.   -- .                                                           .
  6237.   -- .............................................................
  6238.   function Tail_Node (List : LIST_TYPE) return BOOLEAN;
  6239.   --| Purpose
  6240.   --| Indicates whether the "current pointer" references the tail
  6241.   --| of the list.
  6242.   --|
  6243.   --| Exceptions (none)
  6244.   --| Notes (none)
  6245.  
  6246.   -- .............................................................
  6247.   -- .                                                           .
  6248.   -- .  SINGLY_LINKED_LIST.CURRENT_ELEMENT                       .  SPEC
  6249.   -- .                                                           .
  6250.   -- .............................................................
  6251.   function Current_Element (List : LIST_TYPE) return LIST_ELEMENT;
  6252.   --| Purpose
  6253.   --| Returns the value of the element referenced by the "current pointer".
  6254.   --| Raises End_Error if Null_Node(List) = True.
  6255.   --|
  6256.   --| Exceptions
  6257.   --|   End_Error
  6258.   --|
  6259.   --| Notes (none)
  6260.  
  6261.   -- .............................................................
  6262.   -- .                                                           .
  6263.   -- .  SINGLY_LINKED_LIST.FIRST                                 .  SPEC
  6264.   -- .                                                           .
  6265.   -- .............................................................
  6266.   procedure First (List : in out LIST_TYPE);
  6267.   --| Purpose
  6268.   --| Positions the "current pointer" at the head of the list
  6269.   --| (even if the list is empty).
  6270.   --|
  6271.   --| Exceptions (none)
  6272.   --| Notes (none)
  6273.  
  6274.   -- .............................................................
  6275.   -- .                                                           .
  6276.   -- .  SINGLY_LINKED_LIST.NEXT                                  .  SPEC
  6277.   -- .                                                           .
  6278.   -- .............................................................
  6279.   procedure Next (List : in out LIST_TYPE);
  6280.   --| Purpose
  6281.   --| Positions the "current pointer" at the next element in the list.
  6282.   --| After the last element in the list, Null_Node(List) becomes True.
  6283.   --| Raises End_Error if Null_Node(List) = True.
  6284.   --|
  6285.   --| Exceptions
  6286.   --|   End_Error
  6287.   --|
  6288.   --| Notes (none)
  6289.  
  6290.   -- .............................................................
  6291.   -- .                                                           .
  6292.   -- .  SINGLY_LINKED_LIST.INSERT_AFTER                          .  SPEC
  6293.   -- .                                                           .
  6294.   -- .............................................................
  6295.   procedure Insert_After (List    : in out LIST_TYPE;
  6296.                           Element : LIST_ELEMENT);
  6297.   --| Purpose
  6298.   --| Inserts an element after the "current pointer".
  6299.   --| If Null_Node(List) = True the element is appended after
  6300.   --| the tail element.
  6301.   --|
  6302.   --| Exceptions (none)
  6303.   --| Notes (none)
  6304.  
  6305.   -- .............................................................
  6306.   -- .                                                           .
  6307.   -- .  SINGLY_LINKED_LIST.INSERT_BEFORE                         .  SPEC
  6308.   -- .                                                           .
  6309.   -- .............................................................
  6310.   procedure Insert_Before (List    : in out LIST_TYPE;
  6311.                            Element : LIST_ELEMENT);
  6312.   --| Purpose
  6313.   --| Inserts an element before the "current pointer".
  6314.   --| If Null_Node(List) = True the element is prepended before
  6315.   --| the head element.
  6316.   --|
  6317.   --| Exceptions (none)
  6318.   --| Notes (none)
  6319.  
  6320.   -- .............................................................
  6321.   -- .                                                           .
  6322.   -- .  SINGLY_LINKED_LIST.DELETE_ELEMENT                        .  SPEC
  6323.   -- .                                                           .
  6324.   -- .............................................................
  6325.   procedure Delete_Element (List : in out LIST_TYPE);
  6326.   --| Purpose
  6327.   --| Deletes the element referenced by the "current pointer" from the list.
  6328.   --| Upon deletion, the "current pointer" references the element after the
  6329.   --| deleted element.
  6330.   --| Raises End_Error if Null_Node(List) = True.
  6331.   --|
  6332.   --| Exceptions
  6333.   --|   End_Error
  6334.   --|
  6335.   --| Notes (none)
  6336.  
  6337.   -- .............................................................
  6338.   -- .                                                           .
  6339.   -- .  SINGLY_LINKED_LIST.MODIFY                                .  SPEC
  6340.   -- .                                                           .
  6341.   -- .............................................................
  6342.   generic
  6343.     with procedure Transformation (Element : in out LIST_ELEMENT);
  6344.   procedure Modify (List : LIST_TYPE);
  6345.   --| Purpose
  6346.   --| Permits modification of the element referenced by the "current pointer"
  6347.   --| where the modification doesn't require external values (e.g.
  6348.   --| incrementing a field of the element).
  6349.   --| Raises End_Error if Null_Node(List) = True.
  6350.   --|
  6351.   --| Exceptions
  6352.   --|   End_Error
  6353.   --|
  6354.   --| Notes (none)
  6355.  
  6356.   -- .............................................................
  6357.   -- .                                                           .
  6358.   -- .  SINGLY_LINKED_LIST.UPDATE                                .  SPEC
  6359.   -- .                                                           .
  6360.   -- .............................................................
  6361.   generic
  6362.     type UPDATE_INFORMATION is private;
  6363.     with procedure Transformation (Element     : in out LIST_ELEMENT;
  6364.                                    Information : UPDATE_INFORMATION);
  6365.   procedure Update (List        : LIST_TYPE;
  6366.                     Information : UPDATE_INFORMATION);
  6367.   --| Purpose
  6368.   --| Permits modification of the element referenced by the "current pointer"
  6369.   --| where the modification requires external values (e.g. assigning a value
  6370.   --| to a field of the element).
  6371.   --| Raises End_Error if Null_Node(List) = True.
  6372.   --|
  6373.   --| Exceptions
  6374.   --|   End_Error
  6375.   --|
  6376.   --| Notes (none)
  6377.  
  6378. -- Pragmas
  6379.   pragma Inline (Empty, Null_Node, Head_Node, Tail_Node, Current_Element);
  6380.   pragma Inline (Modify, Update);
  6381.  
  6382. private
  6383.   type NODE;
  6384.   type NODE_ACCESS is access NODE;
  6385.   type NODE is
  6386.     record
  6387.       Element : LIST_ELEMENT;
  6388.       Next    : NODE_ACCESS;
  6389.     end record;
  6390.   type LIST_TYPE is
  6391.     record
  6392.       Head     : NODE_ACCESS;
  6393.       Tail     : NODE_ACCESS;
  6394.       Previous : NODE_ACCESS;
  6395.       Current  : NODE_ACCESS;
  6396.     end record;
  6397.  
  6398. end Singly_Linked_List;
  6399. --::::::::::
  6400. --sort.spc
  6401. --::::::::::
  6402. -- *****************************************************
  6403. -- *                                                   *
  6404. -- *  SORT_UTILITIES                                   *  SPEC
  6405. -- *                                                   *
  6406. -- *****************************************************
  6407. with System;  -- predefined package SYSTEM
  6408. generic
  6409.   type COMPONENT_TYPE is private;  -- type of the data components
  6410.   type INDEX_TYPE     is (<>);     -- type of array index
  6411.   type ARRAY_TYPE is array (INDEX_TYPE range <>) of COMPONENT_TYPE;
  6412.   with function "<" (Left,Right : in COMPONENT_TYPE) return BOOLEAN is <>;
  6413.   with function Equal (Left,Right : in COMPONENT_TYPE) return BOOLEAN is "=";
  6414. package Sort_Utilities is
  6415. --| Purpose
  6416. --| Sort_Utilities is a generic sorting package. The Sort subprograms
  6417. --| will sort a one dimensional array of any component type that supports
  6418. --| assignment, equality, and inequality (private types) indexed by
  6419. --| discrete type components. The default linear order is ascending order
  6420. --| but may be overridden by the user. The default sort algorithm,
  6421. --| Quicksort (non-recursive), may also be overridden.
  6422. --|
  6423. --| Note that the component type can be a record type. The Sort subprograms
  6424. --| are not restricted to simple data types. If records are to be sorted,
  6425. --| then the formal generic subprogram parameter "<" must be
  6426. --| specified with by a linear order, e.g., a function provided
  6427. --| as an actual generic subprogram parameter at instantiation.
  6428. --|
  6429. --| Note that the component type can be an access type (which can
  6430. --| point to other objects, improving sort efficiency). If access types
  6431. --| are to be sorted, then the formal generic subprogram parameter "<"
  6432. --| must be specified by a linear order (see example #3 below).
  6433. --| Since access types can be sorted, the Sort routine below can be
  6434. --| used to sort limited types and unconstrained types (designated by
  6435. --| an access type).
  6436. --|
  6437. --| For data in which equality does not truly apply (i.e., real types)
  6438. --| one can use the Equal function to specify an equality operation.
  6439. --| Hence, one can decide that two numbers are "close enough" to be
  6440. --| equal (see example #4 below).
  6441. --|
  6442. --| The number of comparisons and exchanges made to sort the array
  6443. --| can be returned. These numbers should give some indication on how
  6444. --| much work was actually performed by the sorting algorithms. These
  6445. --| numbers can also be used to compare the relative efficiency
  6446. --| of the sorting algorithms.
  6447. --|
  6448. --| This package can be used to sort data on external devices. The user
  6449. --| should use this package to sort a subset of the external data, then
  6450. --| use a merge operation on all sorted subsets. For example, if the
  6451. --| system can only hold 1000 components in RAM, but you need to sort
  6452. --| 3000 components, bring in components #1-1000 and sort them using this
  6453. --| routine, and then write them to a file. Next do the same with
  6454. --| components #1001-2000, and finally with components #2001-3000. Now
  6455. --| merge the three sorted files using a merge package.
  6456. --|
  6457. --| One of the Sort subprograms is a function which can be used to sort
  6458. --| an array and test it against another in an inline expression. This
  6459. --| can be useful when comparing the contents of two arrays which may be
  6460. --| equal, but not at the identical indices. This will be most useful for
  6461. --| comparing the equality of sets implemented as arrays (see example #5
  6462. --| below).
  6463. --|
  6464. --| Other Sort subprograms allow the user to maintain the original state
  6465. --| of the array by returning a new array that is sorted. These subprograms
  6466. --| will be useful in cases where sorting is required, but the original
  6467. --| (unsorted) data must be preserved.
  6468. --|
  6469. --| Design of this package has been documented in the IEEE Computer
  6470. --| Society Second International Conference on Ada Applications and
  6471. --| Environments proceedings. Contact the IEEE or the author for a copy
  6472. --| of the paper. This paper is forthcoming in a special issue of IEEE
  6473. --| Software also.
  6474. --|
  6475. --| Initialization Exceptions (none)
  6476. --|
  6477. --| Notes
  6478. --| See the explanation below for details on the different
  6479. --| sort algorithms available and their respective merits.
  6480. --| There are also examples at the end of this specification
  6481. --| on the use of this package.
  6482. --|
  6483. --| Modifications
  6484. --| Author: Goeff Mendal, Stanford University
  6485.  
  6486.   type SORT_ALGORITHM_TYPE is (Quicksort, Recursive_Quicksort, Bsort,
  6487.     Bubble_Sort, Bubble_Sort_with_Quick_Exit, Selection_Sort, Heapsort,
  6488.     Insertion_Sort, Merge_Sort);
  6489.   -- Users can specify the type of sorting algorithm they want by
  6490.   -- specifying an enumeration literal from the type above. The default
  6491.   -- algorithm, Quicksort (non-recursive), generally performs best.
  6492.   --
  6493.   -- One note about stability of the algorithms: only the Bubble Sorts
  6494.   -- and Insertion Sort are stable algorithms. Thus, they are the
  6495.   -- only algorithms that preserve the ordering of equal components
  6496.   -- without use of a selector function. In all cases, a selector
  6497.   -- function may be specified to introduce stability into the
  6498.   -- sorting algorithms (see example #3 below).
  6499.   --
  6500.   -- Quicksort:   O(NlogN). Is most efficient when used with large, unsorted
  6501.   --              arrays. Uses an explicit stack to maintain state and
  6502.   --              partitions. Instable. This is the default algorithm.
  6503.   -- Recursive_Quicksort:  O(NlogN). Is most efficient when used with large,
  6504.   --              unsorted arrays. Recursive nature may introduce significant
  6505.   --              memory overhead for very large arrays. Instable.
  6506.   -- Bsort:       O(NlogN). Is most efficient when used with large arrays
  6507.   --              that are already sorted, partially sorted, or sorted in
  6508.   --              reverse. Recursive. Instable.
  6509.   -- Bubble_Sort: O(N**2). Is most efficient when used with small
  6510.   --              arrays that are almost already sorted. Non-recursive.
  6511.   --              Brute force. Low memory requirements. Stable.
  6512.   -- Bubble_Sort_with_Quick_Exit: O(N**2). Is most efficient when
  6513.   --              used with small arrays that are almost already sorted.
  6514.   --              Non-recursive. Same as bubble sort above except brute
  6515.   --              force is limited. Stable.
  6516.   -- Selection_Sort: O(N**2). Is most efficient when used with
  6517.   --              small arrays in which the Component_Type is a
  6518.   --              record type. Non-recursive. Brute force. Instable.
  6519.   -- Heapsort:    O(NlogN). Is most efficient when used with
  6520.   --              large, unsorted arrays. Non-recursive. Very low
  6521.   --              memory requirements. Instable.
  6522.   -- Insertion_Sort: O(N**2). Is most efficient when used with
  6523.   --              small arrays that are almost already sorted. Non-
  6524.   --              recursive. Brute force. Stable.
  6525.   -- Merge_Sort:  O(NlogN). Is most efficient when used with medium-large
  6526.   --              arrays. Non-recursive. Instable. Uses an auxiliary array
  6527.   --              to perform merging.
  6528.  
  6529.  
  6530.   type PERFORMANCE_INSTRUMENTATION_TYPE is range -1 .. SYSTEM.MAX_INT;
  6531.   -- This type declaration should be used to specify the
  6532.   -- instrumentation analysis results that can be returned by the Sort
  6533.   -- subprograms below. -1 is only returned if an overflow in calculations
  6534.   -- has occurred. The Sort subprograms will still sort the array if an
  6535.   -- overflow in instrumentation analysis data calculations
  6536.   -- occurs.
  6537.  
  6538.   Sort_Arrays_Length_Mismatch : exception;
  6539.   -- This exception is raised during execution of the Sort
  6540.   -- subprograms which take two arrays as parameters.  These two arrays
  6541.   -- must be of the same length.
  6542.  
  6543.   -- ...................................................
  6544.   -- .                                                 .
  6545.   -- .  SORT_UTILITIES.VERSION                         .  SPEC
  6546.   -- .                                                 .
  6547.   -- ...................................................
  6548.   function Version return STRING;
  6549.   --| Purpose
  6550.   --| Returns the version number of this package.
  6551.   --|
  6552.   --| Exceptions (none)
  6553.   --| Notes (none)
  6554.  
  6555.   -- ...................................................
  6556.   -- .                                                 .
  6557.   -- .  SORT_UTILITIES.SORT                            .  SPEC
  6558.   -- .                                                 .
  6559.   -- ...................................................
  6560.   procedure Sort (
  6561.     Sort_Array             : in out ARRAY_TYPE;
  6562.     Number_of_Comparisons,
  6563.     Number_of_Exchanges    :    out PERFORMANCE_INSTRUMENTATION_TYPE;
  6564.     Sort_Algorithm         : in     SORT_ALGORITHM_TYPE := Quicksort);
  6565.   --| Purpose
  6566.   --| The following procedure will sort a one dimensional array of
  6567.   --| components. It can sort in ascending/descending order or any
  6568.   --| user-defined order. It can sort components of any type that
  6569.   --| support equality, inequality, and assignment (private types).
  6570.   --| The array indices can be of any discrete type. The number of
  6571.   --| comparisons and exchanges can also be returned.
  6572.   --|
  6573.   --| Exceptions (none)
  6574.   --| Notes (none)
  6575.  
  6576.   -- ...................................................
  6577.   -- .                                                 .
  6578.   -- .  SORT_UTILITIES.SORT                            .  SPEC
  6579.   -- .                                                 .
  6580.   -- ...................................................
  6581.   procedure Sort (
  6582.     Sort_Array     : in out ARRAY_TYPE;
  6583.     Sort_Algorithm : in     SORT_ALGORITHM_TYPE := Quicksort);
  6584.   --| Purpose
  6585.   --| This overloading of procedure Sort should be specified
  6586.   --| when no instrumentation analysis data are required.
  6587.   --|
  6588.   --| Exceptions (none)
  6589.   --| Notes (none)
  6590.     
  6591.   -- ...................................................
  6592.   -- .                                                 .
  6593.   -- .  SORT_UTILITIES.SORT                            .  SPEC
  6594.   -- .                                                 .
  6595.   -- ...................................................
  6596.   procedure Sort (
  6597.     Unsorted_Array         : in     ARRAY_TYPE;
  6598.     Sorted_Array           :    out ARRAY_TYPE;
  6599.     Number_of_Comparisons,
  6600.     Number_of_Exchanges    :    out PERFORMANCE_INSTRUMENTATION_TYPE;
  6601.     Sort_Algorithm         : in     SORT_ALGORITHM_TYPE := Quicksort);
  6602.   --| Purpose
  6603.   --| The following overloading of procedure Sort should be used when
  6604.   --| the original data must be preserved and instrumentation analysis
  6605.   --| results are required.
  6606.   --|
  6607.   --| Exceptions
  6608.   --|   Sort_Arrays_Length_Mismatch is raised if Unsorted_Array
  6609.   --|                               and Sorted_Array are not
  6610.   --|                               the same length
  6611.   --|
  6612.   --| Notes (none)
  6613.   
  6614.   -- ...................................................
  6615.   -- .                                                 .
  6616.   -- .  SORT_UTILITIES.SORT                            .  SPEC
  6617.   -- .                                                 .
  6618.   -- ...................................................
  6619.   procedure Sort (
  6620.     Unsorted_Array : in     ARRAY_TYPE;
  6621.     Sorted_Array   :    out ARRAY_TYPE;
  6622.     Sort_Algorithm : in     SORT_ALGORITHM_TYPE := Quicksort);
  6623.   --| Purpose
  6624.   --| The following overloading of procedure Sort should be used when
  6625.   --| the original data must be preserved and no instrumentation analysis
  6626.   --| results are required.
  6627.   --|
  6628.   --| Exceptions
  6629.   --|   Sort_Arrays_Length_Mismatch is raised if Unsorted_Array
  6630.   --|                               and Sorted_Array are not
  6631.   --|                               the same length
  6632.   --|
  6633.   --| Notes (none)
  6634.     
  6635.   -- ...................................................
  6636.   -- .                                                 .
  6637.   -- .  SORT_UTILITIES.SORT                            .  SPEC
  6638.   -- .                                                 .
  6639.   -- ...................................................
  6640.   function Sort (
  6641.     Sort_Array     : in ARRAY_TYPE;
  6642.     Sort_Algorithm : in SORT_ALGORITHM_TYPE := Quicksort)
  6643.     return Array_Type;
  6644.   --| Purpose
  6645.   --| This overloading of function Sort should be used when
  6646.   --| sorting is required in an inline expression.
  6647.  
  6648. end Sort_Utilities;
  6649. --::::::::::
  6650. --stringer.spc
  6651. --::::::::::
  6652. -- *****************************************************************
  6653. -- *                                                               *
  6654. -- *  STRING_MANIPULATOR                                           *  SPEC
  6655. -- *                                                               *
  6656. -- *****************************************************************
  6657. package String_Manipulator is
  6658. --| Purpose   
  6659. --| STRING_MANIPULATOR provides a few routines
  6660. --| for storing string values into different
  6661. --| sizes of strings.
  6662. --|
  6663. --| Initialization Exceptions (none)
  6664. --| Notes (none)
  6665. --|
  6666. --| Modifications
  6667. --| Author: Richard Conn
  6668.    
  6669. -- Exceptions
  6670.   STRING_OVERFLOW : exception; -- raised by GUARDED_LOAD
  6671.    
  6672.   -- .............................................................
  6673.   -- .                                                           .
  6674.   -- .  STRING_MANIPULATOR.LOAD                                  .  SPEC
  6675.   -- .                                                           .
  6676.   -- .............................................................
  6677.   procedure Load (From           : in STRING;
  6678.                   To             : out STRING;
  6679.                   Fill_Character : in CHARACTER := ' ');
  6680.   --| Purpose
  6681.   --| LOAD places the string FROM into the first part of the
  6682.   --| string TO, filling the rest with FILL_CHARACTER; if the string
  6683.   --| FROM is longer than the string TO, the string FROM is truncated
  6684.   --| into TO without warning
  6685.   --|
  6686.   --| Exceptions (none)
  6687.   --| Notes (none)
  6688.    
  6689.   -- .............................................................
  6690.   -- .                                                           .
  6691.   -- .  STRING_MANIPULATOR.LOAD                                  .  SPEC
  6692.   -- .                                                           .
  6693.   -- .............................................................
  6694.   procedure Load (From           : in STRING;
  6695.                   To             : out STRING;
  6696.                   Last           : out NATURAL;
  6697.                   Fill_Character : in CHARACTER := ' ');
  6698.   --| Purpose
  6699.   --| LOAD places the string FROM into the first part of the
  6700.   --| string TO, filling the rest with FILL_CHARACTER; if the string
  6701.   --| FROM is longer than the string TO, the string FROM is truncated
  6702.   --| into TO without warning
  6703.   --|
  6704.   --| Exceptions (none)
  6705.   --| Notes (none)
  6706.    
  6707.   -- .............................................................
  6708.   -- .                                                           .
  6709.   -- .  STRING_MANIPULATOR.GUARDED_LOAD                          .  SPEC
  6710.   -- .                                                           .
  6711.   -- .............................................................
  6712.   procedure Guarded_Load (From           : in STRING;
  6713.                           To             : out STRING;
  6714.                           Fill_Character : in CHARACTER := ' ');
  6715.   --| Purpose
  6716.   --| GUARDED_LOAD places the string FROM into the first part of the
  6717.   --| string TO, filling the rest with FILL_CHARACTER; if the string
  6718.   --| FROM is longer than the string TO, the exception STRING_OVERFLOW is
  6719.   --| raised
  6720.   --|
  6721.   --| Exceptions
  6722.   --|   STRING_OVERFLOW
  6723.   --|
  6724.   --| Notes (none)
  6725.    
  6726.   -- .............................................................
  6727.   -- .                                                           .
  6728.   -- .  STRING_MANIPULATOR.GUARDED_LOAD                          .  SPEC
  6729.   -- .                                                           .
  6730.   -- .............................................................
  6731.   procedure Guarded_Load (From           : in STRING;
  6732.                           To             : out STRING;
  6733.                           Last           : out NATURAL;
  6734.                           Fill_Character : in CHARACTER := ' ');
  6735.   --| Purpose
  6736.   --| GUARDED_LOAD places the string FROM into the first part of the
  6737.   --| string TO, filling the rest with FILL_CHARACTER; if the string
  6738.   --| FROM is longer than the string TO, the exception STRING_OVERFLOW is
  6739.   --| raised
  6740.   --|
  6741.   --| Exceptions
  6742.   --|   STRING_OVERFLOW
  6743.   --|
  6744.   --| Notes (none)
  6745.    
  6746.   -- .............................................................
  6747.   -- .                                                           .
  6748.   -- .  STRING_MANIPULATOR.FILL                                  .  SPEC
  6749.   -- .                                                           .
  6750.   -- .............................................................
  6751.   procedure Fill (What      : out STRING;
  6752.                   With_Item : in CHARACTER := ' ');
  6753.   --| Purpose
  6754.   --| FILL fills the string WHAT with the indicated WITH_ITEM
  6755.   --|
  6756.   --| Exceptions (none)
  6757.   --| Notes (none)
  6758.    
  6759.   -- .............................................................
  6760.   -- .                                                           .
  6761.   -- .  STRING_MANIPULATOR.IS_FILLED                             .  SPEC
  6762.   -- .                                                           .
  6763.   -- .............................................................
  6764.   function Is_Filled (What      : in STRING;
  6765.                       With_Item : in CHARACTER := ' ') return BOOLEAN;
  6766.   --| Purpose
  6767.   --| IS_FILLED returns TRUE if the string WHAT contains only the
  6768.   --| character WITH_ITEM; IS_FILLED returns FALSE otherwise
  6769.   --|
  6770.   --| Exceptions (none)
  6771.   --| Notes (none)
  6772.    
  6773. end String_Manipulator;
  6774. --::::::::::
  6775. --testlog.spc
  6776. --::::::::::
  6777. -- **************************************************
  6778. -- *                                                *
  6779. -- *  Test_Log                                      *  SPEC
  6780. -- *                                                *
  6781. -- **************************************************
  6782. package Test_Log is
  6783. --| Purpose
  6784. --| A Test Log is a log of test activity.  Expected and
  6785. --| Actual test results can be reported to it via the Compare
  6786. --| routines, and Test Log can build a summary report of
  6787. --| the test results.  It keeps track of the number of
  6788. --| tests and the number of errors detected.
  6789. --|
  6790. --| Test_Log provides a number of Compare routines
  6791. --| that compare one value with another and two counters.
  6792. --| The Test Counter is incremented each time a Compare
  6793. --| routine is called and the Error counter is
  6794. --| incremented each time the comparison does not work
  6795. --| out.
  6796. --|
  6797. --| Test_Log performs its operations in one of three modes
  6798. --| which may be selected by calling the Set_Mode routine:
  6799. --|   SILENT           all results of calls to Compare are
  6800. --|                    logged internally and no display is
  6801. --|                    generated except when the Report
  6802. --|                    routine is called
  6803. --|   VERBOSE          all results of calls to Compare are
  6804. --|                    displayed on the console
  6805. --|   REPORT_TO_FILE   same as VERBOSE, except the results
  6806. --|                    are written to a file rather than to
  6807. --|                    the console
  6808. --|
  6809. --| A fourth "mode" is USER_SELECTABLE, which results in a
  6810. --| prompt being displayed to the user and the user selecting
  6811. --| one of the modes SILENT, VERBOSE, or REPORT_TO_FILE.
  6812. --|
  6813. --| Initialization Exceptions (none)
  6814. --| Notes
  6815. --|    The Test and Error counters are initially set to
  6816. --| zero.  They may be reset to zero at any time by
  6817. --| calling the Reset procedure.
  6818. --|    The Test and Error counters are of type NATURAL,
  6819. --| so care should be exercised to see that no more
  6820. --| tests than NATURAL'LAST are done before a Reset.
  6821. --|
  6822. --| Modifications
  6823. --| 2/27/91  Richard Conn   Initial Version and Release
  6824.  
  6825.   REPORT_FILE_ERROR : exception;
  6826.   -- raised if output report file cannot be created
  6827.  
  6828.   Test_Log_File : constant STRING := "testlog.rpt";
  6829.   -- Name of test log file (see next comment)
  6830.  
  6831.   type MODE is (SILENT, VERBOSE, REPORT_TO_FILE, USER_SELECTABLE);
  6832.   -- The Test Log can run silently, displaying a summary report
  6833.   -- at the end, or verbosely, displaying each comparison as it
  6834.   -- is done.  The REPORT_TO_FILE mode is the same as VERBOSE,
  6835.   -- but the output is sent to Test_Log_File rather than the
  6836.   -- console.  USER_SELECTABLE causes the user to be prompted at
  6837.   -- the console and manually select the SILENT, VERBOSE, or
  6838.   -- REPORT_TO_FILE modes.
  6839.  
  6840.   type TEST_RESULT is (FAIL, PASS);
  6841.   -- Values of the result of a test
  6842.  
  6843.   -- ..................................................
  6844.   -- .                                                .
  6845.   -- .  Test_Log.Set_Mode                             .  SPEC
  6846.   -- .                                                .
  6847.   -- ..................................................
  6848.   procedure Set_Mode (To : in MODE);
  6849.   --| Purpose
  6850.   --| The mode of operation is set to the indicated mode.
  6851.   --| See the discussion above for a description of the
  6852.   --| modes.
  6853.   --|
  6854.   --| Exceptions (none)
  6855.   --| Notes
  6856.   --|   If this routine is not called, the default mode
  6857.   --| is SILENT.
  6858.  
  6859.   -- ..................................................
  6860.   -- .                                                .
  6861.   -- .  Test_Log.Set_Test_ID_Field_Width              .  SPEC
  6862.   -- .                                                .
  6863.   -- ..................................................
  6864.   procedure Set_Test_ID_Field_Width (To : in NATURAL := 10);
  6865.   --| Purpose
  6866.   --| Set the length of a test ID to be output (up to 60).
  6867.   --| Any test ID string shorter than this length will be
  6868.   --| padded with spaces.  Any test ID string longer than
  6869.   --| this length will be output in full.
  6870.   --|
  6871.   --| Exceptions (none)
  6872.   --| Notes
  6873.   --|   If this routine is not called, the field width is
  6874.   --| automatically set to the default value.
  6875.  
  6876.   -- ..................................................
  6877.   -- .                                                .
  6878.   -- .  Test_Log.Set_String_Field_Width               .  SPEC
  6879.   -- .                                                .
  6880.   -- ..................................................
  6881.   procedure Set_String_Field_Width (To : in NATURAL := 20);
  6882.   --| Purpose
  6883.   --| Set the length of a string to be output (up to 60).
  6884.   --| Any string shorter than this length will be padded
  6885.   --| with spaces.  Any string longer than this length
  6886.   --| will be output in full.
  6887.   --|
  6888.   --| Exceptions (none)
  6889.   --| Notes
  6890.   --|   If this routine is not called, the field width is
  6891.   --| automatically set to the default value.
  6892.  
  6893.   -- ..................................................
  6894.   -- .                                                .
  6895.   -- .  Test_Log.Set_Integer_Field_Width              .  SPEC
  6896.   -- .                                                .
  6897.   -- ..................................................
  6898.   procedure Set_Integer_Field_Width (To : in NATURAL := 20);
  6899.   --| Purpose
  6900.   --| Set the length of an integer to be output.
  6901.   --| If the integer requires more space than this,
  6902.   --| the necessary space will be taken.
  6903.   --|
  6904.   --| Exceptions (none)
  6905.   --| Notes
  6906.   --|   If this routine is not called, the field width is
  6907.   --| automatically set to the default value.
  6908.  
  6909.   -- ..................................................
  6910.   -- .                                                .
  6911.   -- .  Test_Log.Set_Float_Field_Width                .  SPEC
  6912.   -- .                                                .
  6913.   -- ..................................................
  6914.   procedure Set_Float_Field_Width
  6915.     (Before_Decimal : in NATURAL := 2;
  6916.      After_Decimal  : in NATURAL := 5;
  6917.      In_Exponent    : in NATURAL := 4);
  6918.   --| Purpose
  6919.   --| Set the length of the fields of a floating point
  6920.   --| value to be output.  If In_Exponent is non-zero,
  6921.   --| scientific notation is used; if In_Exponent is
  6922.   --| zero, fixed point notation is used.
  6923.   --|
  6924.   --| Exceptions (none)
  6925.   --| Notes
  6926.   --|   If this routine is not called, the field widths are
  6927.   --| automatically set to the default values.
  6928.  
  6929.   -- ..................................................
  6930.   -- .                                                .
  6931.   -- .  Test_Log.Reset                                .  SPEC
  6932.   -- .                                                .
  6933.   -- ..................................................
  6934.   procedure Reset;
  6935.   --| Purpose
  6936.   --| The Reset routine resets the test and error counters.
  6937.   --| It need not be called the first time this package's
  6938.   --| routines are used since these counters come up
  6939.   --| initialized.
  6940.   --|
  6941.   --| Exceptions (none)
  6942.  
  6943.   -- ..................................................
  6944.   -- .                                                .
  6945.   -- .  Test_Log.Compare                              .  SPEC
  6946.   -- .                                                .
  6947.   -- ..................................................
  6948.   procedure Compare(Test_ID         : in STRING;
  6949.                     Expected_Result : in STRING;
  6950.                     Actual_Result   : in STRING);
  6951.   procedure Compare(Test_ID         : in STRING;
  6952.                     Expected_Result : in INTEGER;
  6953.                     Actual_Result   : in INTEGER);
  6954.   procedure Compare(Test_ID         : in STRING;
  6955.                     Expected_Result : in FLOAT;
  6956.                     Actual_Result   : in FLOAT;
  6957.                     Tolerance       : in FLOAT);
  6958.   --| Purpose
  6959.   --| These routines compare the two values (x1 and x2) for
  6960.   --| equality (except in the case of F1 and F2, which are
  6961.   --| compared by abs(F1-F2)<Tolerance).  If these values
  6962.   --| are equal or within tolerance, then only the
  6963.   --| Test counter is incremented.  If these values are
  6964.   --| not equal or within tolerance, the Test counter and
  6965.   --| Error counter are incremented and the Test_ID is
  6966.   --| displayed.
  6967.   --|
  6968.   --| If the Mode (see the Set_Mode procedure) is SILENT,
  6969.   --| the results are not shown.  If the Mode is VERBOSE
  6970.   --| or REPORT_TO_FILE, then the Test_ID, the Expected_Result,
  6971.   --| the Actual_Result, and the result of the comparison
  6972.   --| (FAIL or PASS) is written to the console (VERBOSE)
  6973.   --| or the output file Test_Log_File (REPORT_TO_FILE).
  6974.   --|
  6975.   --| Exceptions (none)
  6976.  
  6977.   -- ..................................................
  6978.   -- .                                                .
  6979.   -- .  Test_Log.Enter_Test_Result                    .  SPEC
  6980.   -- .                                                .
  6981.   -- ..................................................
  6982.   procedure Enter_Test_Result
  6983.       (Test_ID : in STRING;
  6984.        Result  : in TEST_RESULT);
  6985.   --| Purpose
  6986.   --| This routine enters Result as though a Compare call
  6987.   --| was made.  This is the same as calling one of the
  6988.   --| Compare routines, but the result of the comparison
  6989.   --| is the input value to this routine and no comparison
  6990.   --| is actually done.  This is useful when a test does
  6991.   --| not generate a value as a result, such as when the
  6992.   --| test expects an exception to be raised.
  6993.   --|
  6994.   --| See the Purpose section of the Compare routines
  6995.   --| for more information.
  6996.   --|
  6997.   --| Exceptions (none)
  6998.  
  6999.   -- ..................................................
  7000.   -- .                                                .
  7001.   -- .  Test_Log.Error_Count                          .  SPEC
  7002.   -- .                                                .
  7003.   -- ..................................................
  7004.   function Error_Count return NATURAL;
  7005.   --| Purpose
  7006.   --| Error_Count returns the value of the Error Counter.
  7007.   --|
  7008.   --| Exceptions (none)
  7009.  
  7010.   -- ..................................................
  7011.   -- .                                                .
  7012.   -- .  Test_Log.Test_Count                           .  SPEC
  7013.   -- .                                                .
  7014.   -- ..................................................
  7015.   function Test_Count return NATURAL;
  7016.   --| Purpose
  7017.   --| Test_Count returns the value of the Test Counter.
  7018.   --|
  7019.   --| Exceptions (none)
  7020.  
  7021.   -- ..................................................
  7022.   -- .                                                .
  7023.   -- .  Test_Log.Write                                .  SPEC
  7024.   -- .                                                .
  7025.   -- ..................................................
  7026.   procedure Write(Message : in STRING := "");
  7027.   --| Purpose
  7028.   --| Write the message to the console followed by a
  7029.   --| New Line.
  7030.   --|
  7031.   --| Exceptions (none)
  7032.  
  7033.   -- ..................................................
  7034.   -- .                                                .
  7035.   -- .  Test_Log.Report                               .  SPEC
  7036.   -- .                                                .
  7037.   -- ..................................................
  7038.   procedure Report(Message : in STRING := "");
  7039.   --| Purpose
  7040.   --| Print a report showing the values of the Test and
  7041.   --| Error Counters.  If Message is not null, it is
  7042.   --| printed, indented, before the counter values.
  7043.   --|
  7044.   --| Exceptions (none)
  7045.  
  7046.   -- ..................................................
  7047.   -- .                                                .
  7048.   -- .  Test_Log.Close                                .  SPEC
  7049.   -- .                                                .
  7050.   -- ..................................................
  7051.   procedure Close;
  7052.   --| Purpose
  7053.   --| Close the Test Log.  If a Test_Log_File is open,
  7054.   --| it is closed.
  7055.   --|
  7056.   --| Exceptions (none)
  7057.  
  7058. end Test_Log;
  7059. --::::::::::
  7060. --binfile.spc
  7061. --::::::::::
  7062. -- **************************************************
  7063. -- *                                                *
  7064. -- *  Binary_File                                   *  SPEC
  7065. -- *                                                *
  7066. -- **************************************************
  7067. with CS_Parts_Types;  -- for BYTE type
  7068. use  CS_Parts_Types;
  7069. package Binary_File is
  7070. --| Purpose
  7071. --| Binary_File provides a convenient mechanism for accessing
  7072. --| binary files, implemented as an abstract data type.  The
  7073. --| binary file may be read or written one byte at a time.
  7074. --|
  7075. --| Initialization Exceptions (none)
  7076. --| Notes (none)
  7077. --|
  7078. --| Modifications
  7079. --| 7/15/90  Rick Conn  Initial Design and Code
  7080.  
  7081.   type FILE_TYPE is limited private;
  7082.  
  7083.   type FILE_MODE is (IN_FILE, OUT_FILE);
  7084.   type BLOCK is array (INTEGER range <>) of BYTE;
  7085.  
  7086.   Data_Error,      -- full BLOCK could not be read
  7087.   Device_Error,    -- problem with underlying system
  7088.   End_Error,       -- read attempted into end of file
  7089.   Mode_Error,      -- read attempted from output file, etc.
  7090.   Name_Error,      -- invalid file/dir name
  7091.   Status_Error,    -- file already open
  7092.   Use_Error,       -- write to read/only file, others
  7093.   Unexpected_Error
  7094.     : exception;
  7095.  
  7096.   -- ...................................................
  7097.   -- .                                                 .
  7098.   -- .  Binary_File.Create                             .  SPEC
  7099.   -- .                                                 .
  7100.   -- ...................................................
  7101.   procedure Create (File : in out FILE_TYPE;
  7102.                     Name : in STRING);
  7103.   --| Purpose
  7104.   --| Create a binary file and open it for output.
  7105.   --|
  7106.   --| Exceptions
  7107.   --|   Device_Error   -- raised if file cannot be created
  7108.   --|                  -- due to a hardware error
  7109.   --|   Name_Error     -- raised if Name is not a valid file
  7110.   --|                  -- or directory reference
  7111.   --|   Status_Error   -- raised if file Name is already
  7112.   --|                  -- open
  7113.   --|   Use_Error      -- raised if file Name exists and is
  7114.   --|                  -- read/only
  7115.   --|
  7116.   --| Notes (none)
  7117.  
  7118.   -- ...................................................
  7119.   -- .                                                 .
  7120.   -- .  Binary_File.Open                               .  SPEC
  7121.   -- .                                                 .
  7122.   -- ...................................................
  7123.   procedure Open   (File : in out FILE_TYPE;
  7124.                     Name : in STRING);
  7125.   --| Purpose
  7126.   --| Open an existing binary file for input.
  7127.   --|
  7128.   --| Exceptions
  7129.   --|   Device_Error   -- raised if file cannot be opened
  7130.   --|                  -- due to a hardware error
  7131.   --|   Name_Error     -- raised if Name is not a valid file
  7132.   --|                  -- or directory reference
  7133.   --|   Status_Error   -- raised if file Name is already
  7134.   --|                  -- open
  7135.   --|   Use_Error      -- raised if file Name is write/only
  7136.   --|
  7137.   --| Notes (none)
  7138.  
  7139.   -- ...................................................
  7140.   -- .                                                 .
  7141.   -- .  Binary_File.Close                              .  SPEC
  7142.   -- .                                                 .
  7143.   -- ...................................................
  7144.   procedure Close (File : in out FILE_TYPE);
  7145.   --| Purpose
  7146.   --| Close the indicated file.
  7147.   --|
  7148.   --| Exceptions (none)
  7149.   --| Notes (none)
  7150.  
  7151.   -- ...................................................
  7152.   -- .                                                 .
  7153.   -- .  Binary_File.Reset                              .  SPEC
  7154.   -- .                                                 .
  7155.   -- ...................................................
  7156.   procedure Reset (File : in out FILE_TYPE;
  7157.                    Mode : in FILE_MODE := IN_FILE);
  7158.   --| Purpose
  7159.   --| Close the indicated file and reopen it (at the
  7160.   --| beginning) for input or output.
  7161.   --|
  7162.   --| Exceptions
  7163.   --|   Device_Error   -- raised if file cannot be accessed
  7164.   --|                  -- due to a hardware error
  7165.   --|   Name_Error     -- raised if Name is not a valid file
  7166.   --|                  -- or directory reference
  7167.   --|   Status_Error   -- raised if file Name is already
  7168.   --|                  -- open
  7169.   --|   Use_Error      -- raised if file Name exists and is
  7170.   --|                  -- read/only
  7171.   --|
  7172.   --| Notes (none)
  7173.  
  7174.   -- ...................................................
  7175.   -- .                                                 .
  7176.   -- .  Binary_File.Mode                               .  SPEC
  7177.   -- .                                                 .
  7178.   -- ...................................................
  7179.   function Mode (File : in FILE_TYPE) return FILE_MODE;
  7180.   --| Purpose
  7181.   --| Return the mode (IN_FILE or OUT_FILE) of the
  7182.   --| indicated File.
  7183.   --|
  7184.   --| Exceptions (none)
  7185.   --| Notes (none)
  7186.  
  7187.   -- ...................................................
  7188.   -- .                                                 .
  7189.   -- .  Binary_File.Name                               .  SPEC
  7190.   -- .                                                 .
  7191.   -- ...................................................
  7192.   function Name (File : in FILE_TYPE) return STRING;
  7193.   --| Purpose
  7194.   --| Return the name of the indicated File.
  7195.   --|
  7196.   --| Exceptions (none)
  7197.   --| Notes (none)
  7198.  
  7199.   -- ...................................................
  7200.   -- .                                                 .
  7201.   -- .  Binary_File.Is_Open                            .  SPEC
  7202.   -- .                                                 .
  7203.   -- ...................................................
  7204.   function Is_Open (File : in FILE_TYPE) return BOOLEAN;
  7205.   --| Purpose
  7206.   --| Return TRUE iff the indicated File is open.
  7207.   --|
  7208.   --| Exceptions (none)
  7209.   --| Notes (none)
  7210.  
  7211.   -- ...................................................
  7212.   -- .                                                 .
  7213.   -- .  Binary_File.Is_End                             .  SPEC
  7214.   -- .                                                 .
  7215.   -- ...................................................
  7216.   function Is_End  (File : in FILE_TYPE) return BOOLEAN;
  7217.   --| Purpose
  7218.   --| Return TRUE if the next byte to be returned from
  7219.   --| the indicated File is beyond the end of the file.
  7220.   --|
  7221.   --| Exceptions (none)
  7222.   --| Notes (none)
  7223.  
  7224.   -- ...................................................
  7225.   -- .                                                 .
  7226.   -- .  Binary_File.Read                               .  SPEC
  7227.   -- .                                                 .
  7228.   -- ...................................................
  7229.   procedure Read  (File : in FILE_TYPE;
  7230.                    Item : out BYTE);
  7231.   --| Purpose
  7232.   --| Read the next byte from an OPENed File.
  7233.   --|
  7234.   --| Exceptions
  7235.   --|   Device_Error   -- raised if File cannot be accessed
  7236.   --|                  -- due to a hardware error
  7237.   --|   End_Error      -- raised if the next byte to be
  7238.   --|                  -- returned is beyond the end of
  7239.   --|                  -- the File
  7240.   --|   Mode_Error     -- raised if File is opened for
  7241.   --|                  -- output (mode OUT_FILE)
  7242.   --|   Status_Error   -- raised if File has not been
  7243.   --|                  -- OPENed
  7244.   --|
  7245.   --| Notes (none)
  7246.  
  7247.   -- ...................................................
  7248.   -- .                                                 .
  7249.   -- .  Binary_File.Read                               .  SPEC
  7250.   -- .                                                 .
  7251.   -- ...................................................
  7252.   procedure Read  (File : in FILE_TYPE;
  7253.                    Item : out BLOCK);
  7254.   --| Purpose
  7255.   --| Read the next block from an OPENed File.
  7256.   --|
  7257.   --| Exceptions
  7258.   --|   Data_Error     -- raised if a full BLOCK could
  7259.   --|                  -- not be read from the file
  7260.   --|   Device_Error   -- raised if File cannot be accessed
  7261.   --|                  -- due to a hardware error
  7262.   --|   End_Error      -- raised if the next byte to be
  7263.   --|                  -- returned is beyond the end of
  7264.   --|                  -- the File
  7265.   --|   Mode_Error     -- raised if File is opened for
  7266.   --|                  -- output (mode OUT_FILE)
  7267.   --|   Status_Error   -- raised if File has not been
  7268.   --|                  -- OPENed
  7269.   --|
  7270.   --| Notes (none)
  7271.  
  7272.   -- ...................................................
  7273.   -- .                                                 .
  7274.   -- .  Binary_File.Write                              .  SPEC
  7275.   -- .                                                 .
  7276.   -- ...................................................
  7277.   procedure Write (File : in FILE_TYPE;
  7278.                    Item : in BYTE);
  7279.   --| Purpose
  7280.   --| Write the next byte to a CREATEed File.
  7281.   --|
  7282.   --| Exceptions
  7283.   --|   Device_Error   -- raised if File cannot be accessed
  7284.   --|                  -- due to a hardware error
  7285.   --|   Mode_Error     -- raised if File is opened for
  7286.   --|                  -- input (mode IN_FILE)
  7287.   --|   Status_Error   -- raised if File has not been
  7288.   --|                  -- CREATEd
  7289.   --|
  7290.   --| Notes (none)
  7291.  
  7292.   -- ...................................................
  7293.   -- .                                                 .
  7294.   -- .  Binary_File.Write                              .  SPEC
  7295.   -- .                                                 .
  7296.   -- ...................................................
  7297.   procedure Write (File : in FILE_TYPE;
  7298.                    Item : in BLOCK);
  7299.   --| Purpose
  7300.   --| Write the next block to a CREATEed File.
  7301.   --|
  7302.   --| Exceptions
  7303.   --|   Device_Error   -- raised if File cannot be accessed
  7304.   --|                  -- due to a hardware error
  7305.   --|   Mode_Error     -- raised if File is opened for
  7306.   --|                  -- input (mode IN_FILE)
  7307.   --|   Status_Error   -- raised if File has not been
  7308.   --|                  -- CREATEd
  7309.   --|
  7310.   --| Notes (none)
  7311.  
  7312. private
  7313.   type FILE_OBJECT;  -- deferred to body
  7314.   type FILE_TYPE is access FILE_OBJECT;
  7315. end Binary_File;
  7316. --::::::::::
  7317. --bintree2.spc
  7318. --::::::::::
  7319. -- ***********************************************
  7320. -- *                                             *
  7321. -- *  BINARYTREES                                *  SPEC
  7322. -- *                                             *
  7323. -- ***********************************************
  7324. with Lists;
  7325. generic
  7326.     type ITEMTYPE is private; 
  7327.     with function "<" (X,Y: in ITEMTYPE) return BOOLEAN;
  7328. package BinaryTrees is 
  7329. --| Purpose
  7330. --| This package creates an ordered binary tree.  This will allow for 
  7331. --| quick insertion, and search.  
  7332. --|
  7333. --| The tree is organized such that 
  7334. --|  
  7335. --|  leftchild < root    root < rightchild
  7336. --| 
  7337. --| This means that by doing a left to right search of the tree will can
  7338. --| produce the nodes of the tree in ascending order.
  7339. --|
  7340. --| Initialization Exceptions (none)
  7341. --| Notes (none)
  7342. --|
  7343. --| Modifications
  7344. --| Author: Bill Toscano and Michael Gordon, Intermetrics
  7345.  
  7346.   type TREE is  private;     -- This is the type exported to represent the
  7347.                              -- tree.
  7348.  
  7349.  
  7350.   type TREEITER is private;  -- This is the type which is used to iterate
  7351.                              -- over the set.
  7352.  
  7353.   -- .................................................
  7354.   -- .                                               .
  7355.   -- .  BINARYTREES.CREATE                           .  SPEC
  7356.   -- .                                               .
  7357.   -- .................................................
  7358.   function Create return TREE;
  7359.   --| Purpose
  7360.   --| This creates a tree containing no information and no children. 
  7361.   --|
  7362.   --| Exceptions (none)
  7363.   --| Notes (none)
  7364.  
  7365.   -- .................................................
  7366.   -- .                                               .
  7367.   -- .  BINARYTREES.DEPOSIT                          .  SPEC
  7368.   -- .                                               .
  7369.   -- .................................................
  7370.   procedure Deposit (I : in ITEMTYPE; S : in TREE);
  7371.   --| Purpose
  7372.   --| This changes the information stored at the root of the tree S.
  7373.   --| It deposits the information I in the root of S.
  7374.   --|
  7375.   --| Exceptions (none)
  7376.   --| Notes (none)
  7377.  
  7378.   -- .................................................
  7379.   -- .                                               .
  7380.   -- .  BINARYTREES.DESTROYTREE                      .  SPEC
  7381.   -- .                                               .
  7382.   -- .................................................
  7383.   procedure DestroyTree (T  :in out TREE);
  7384.   --| Purpose
  7385.   --| Destroys a tree and returns the space which it is occupying.
  7386.   --|
  7387.   --| Exceptions (none)
  7388.   --| Notes (none)
  7389.  
  7390.   -- .................................................
  7391.   -- .                                               .
  7392.   -- .  BINARYTREES.INSERTNODE                       .  SPEC
  7393.   -- .                                               .
  7394.   -- .................................................
  7395.   Procedure Insertnode(N      : In Out ITEMTYPE; 
  7396.                        T      : In Out TREE;
  7397.                        Root   : Out TREE; 
  7398.                        Exists : out BOOLEAN); 
  7399.   --| Purpose
  7400.   --| This adds the node N to the tree T inserting in the proper position.
  7401.   --| Root is the root of the subtree which Node N heads (the position
  7402.   --| of Node N in T).
  7403.   --|
  7404.   --| Exceptions (none)
  7405.   --| Notes (none)
  7406.  
  7407.   -- .................................................
  7408.   -- .                                               .
  7409.   -- .  BINARYTREES.MAKETREEITER                     .  SPEC
  7410.   -- .                                               .
  7411.   -- .................................................
  7412.   function MakeTreeIter (T : in TREE) return TREEITER;
  7413.   --| Purpose
  7414.   --| Sets a variable to a position in the tree where the iteration is
  7415.   --| to begin.  In this case, the position is a pointer to the deepest
  7416.   --| leftmost leaf in the tree.
  7417.   --|
  7418.   --| Exceptions (none)
  7419.   --| Notes (none)
  7420.  
  7421.   -- .................................................
  7422.   -- .                                               .
  7423.   -- .  BINARYTREES.MORE                             .  SPEC
  7424.   -- .                                               .
  7425.   -- .................................................
  7426.   function More (I : in TREEITER) return BOOLEAN;
  7427.   --| Purpose
  7428.   --| Returns TRUE iff there are more elements in the tree
  7429.   --| over which to iterate.
  7430.   --|
  7431.   --| Exceptions (none)
  7432.   --| Notes (none)
  7433.  
  7434.   -- .................................................
  7435.   -- .                                               .
  7436.   -- .  BINARYTREES.NEXT                             .  SPEC
  7437.   -- .                                               .
  7438.   -- .................................................
  7439.   procedure Next (I    : in out TREEITER;
  7440.                   Info : out ITEMTYPE);    
  7441.   --| Purpose
  7442.   --| This is the iterator operation.  Given an Iter in the Tree, it
  7443.   --| returns the item Iter points to and updates the Iter.  If Iter
  7444.   --| is at the end of the Tree, More will indicate such.
  7445.   --|
  7446.   --| Exceptions (none)
  7447.   --| Notes (none)
  7448.  
  7449. private
  7450.    type NODE;
  7451.    type TREE is access NODE;
  7452.    type NODE is 
  7453.         record
  7454.             Info           : ITEMTYPE;
  7455.             LeftChild      : TREE;
  7456.             RightChild     : TREE;
  7457.         end record;
  7458.  
  7459.    package NodeOrder is new Lists (TREE);
  7460.  
  7461.    type TREEITER is
  7462.       record
  7463.           NodeList : NodeOrder.LIST;
  7464.           State    : NodeOrder.LISTITER;
  7465.       end record;
  7466.  
  7467. end BinaryTrees;
  7468. --::::::::::
  7469. --hashmap.spc
  7470. --::::::::::
  7471. -- ******************************************************
  7472. -- *                                                    *
  7473. -- *  Hashed_Mapping_PKG                                *  SPEC
  7474. -- *                                                    *
  7475. -- ******************************************************
  7476. with lists;       -- Lists used in implementation.  (private)
  7477. pragma elaborate(lists);
  7478. generic
  7479.   type KEY_TYPE is private;
  7480.   with function Equal (K1, K2: KEY_TYPE) return BOOLEAN is "=";
  7481.   type BUCKET_RANGE is range <>;
  7482.     -- Defines the number of hash buckets, one for each member
  7483.     -- of BUCKET_RANGE.
  7484.   with function Hash (K: KEY_TYPE) return BUCKET_RANGE;
  7485.     -- Required property: equal(e1, e2) => hash(e1) = hash(e2).
  7486.     -- Best results if hash produces a uniform distribution
  7487.     -- over BUCKET_RANGE.
  7488.   type VALUE_TYPE is private;
  7489. package Hashed_Mapping_PKG is
  7490. --| Purpose
  7491. --| This package provides a mapping from one arbitrary type,
  7492. --| KEY_TYPE, to another arbitrary type, VALUE_TYPE.  These
  7493. --| types are generic formals to the package, along with an
  7494. --| equality relation on KEY_TYPE, an integer subtype that
  7495. --| determines the number of hash buckets, and a hashing
  7496. --| function on KEY_TYPE that maps to that integer subtype.
  7497. --|
  7498. --| For the purpose of specifying the operations in this
  7499. --| package, we will view a mapping as a set of bindings,
  7500. --| or key/value pairs.  This allows the use of set notation
  7501. --| in description.
  7502. --|
  7503. --| Initialization Exceptions (none)
  7504. --| Notes (none)
  7505. --|
  7506. --| Modifications
  7507. --| Author: Ron Kownacki, Intermetrics
  7508.  
  7509.   type MAPPING is private;
  7510.  
  7511.   No_More: exception;
  7512.     -- Raised on incorrect use of an iterator.
  7513.   Uninitialized_Mapping: exception;
  7514.     -- Raised on use of an unitialized MAPPING by most operations.
  7515.   Already_Bound: exception;
  7516.     -- Raised on attempt to rebind a key that is currently bound.
  7517.   Not_Bound: exception;
  7518.     -- Raised when a key that is expected to be bound is unbound.
  7519.  
  7520.   type KEYS_ITER is private;     -- Bound keys in arbitrary order.
  7521.   type VALUES_ITER is private;   -- Bound values in arbitrary order.
  7522.   type BINDINGS_ITER is private; -- Key,value pairs in arbitrary order
  7523.  
  7524.   -- .......................................................
  7525.   -- .                                                     .
  7526.   -- .  Hashed_Mapping_PKG.Create                          .  SPEC
  7527.   -- .                                                     .
  7528.   -- .......................................................
  7529.   function Create return MAPPING;
  7530.   --| Purpose
  7531.   --| Return {}.
  7532.   --|
  7533.   --| Exceptions (none)
  7534.   --| Notes (none)
  7535.  
  7536.   -- .......................................................
  7537.   -- .                                                     .
  7538.   -- .  Hashed_Mapping_PKG.Bind                            .  SPEC
  7539.   -- .                                                     .
  7540.   -- .......................................................
  7541.   procedure Bind (Map:   in out MAPPING;
  7542.                   Key:   in     KEY_TYPE;
  7543.                   Value: in     VALUE_TYPE);
  7544.   --| Purpose
  7545.   --| Insert the binding, <key, value>, into map.  Raises
  7546.   --| already_bound iff a pair, <k', v'>, where equal(key, k'),
  7547.   --| is in map.  Raises Uninitialized_Mapping iff map has
  7548.   --| not been initialized.
  7549.   --|
  7550.   --| Exceptions
  7551.   --|   Already_Bound
  7552.   --|   Uninitialized_Mapping
  7553.   --|
  7554.   --| Notes (none)
  7555.  
  7556.   -- .......................................................
  7557.   -- .                                                     .
  7558.   -- .  Hashed_Mapping_PKG.Unbind                          .  SPEC
  7559.   -- .                                                     .
  7560.   -- .......................................................
  7561.   procedure Unbind (Map: in out MAPPING;
  7562.                     Key: in     KEY_TYPE);
  7563.   --| Purpose
  7564.   --| If <k, v>, where equal(key, k), is in map, then removes
  7565.   --| <k, v> from map.  Raises not_bound if no such pair exists.
  7566.   --| Raises Uninitialized_Mapping iff map has not been initialized.
  7567.   --|
  7568.   --| Exceptions
  7569.   --|   Not_Bound
  7570.   --|   Uninitialized_Mapping
  7571.   --|
  7572.   --| Notes (none)
  7573.  
  7574.   -- .......................................................
  7575.   -- .                                                     .
  7576.   -- .  Hashed_Mapping_PKG.Copy                            .  SPEC
  7577.   -- .                                                     .
  7578.   -- .......................................................
  7579.   function Copy (Map: MAPPING) return MAPPING;
  7580.   --| Purpose
  7581.   --| Returns a copy of map.  Subsequent changes to map will not be
  7582.   --| visible through applying operations to the copy of map.
  7583.   --| Assignment or parameter passing without copying will result
  7584.   --| in a single MAPPING value being shared among MAPPING objects.
  7585.   --| Raises Uninitialized_Mapping iff map has not been initialized.
  7586.   --| The assignment operation is used to transfer the values of the
  7587.   --| KEY_TYPE and VALUE_TYPE type COMPONENTs of map; consequently,
  7588.   --| changes in the values of these types may be observable through
  7589.   --| both MAPPINGs if these are access types, or if they contain
  7590.   --| COMPONENTs of an access type.
  7591.   --|
  7592.   --| Exceptions
  7593.   --|   Uninitialized_Mapping
  7594.   --|
  7595.   --| Notes (none)
  7596.  
  7597. -- Query Operations:
  7598.  
  7599.   -- .......................................................
  7600.   -- .                                                     .
  7601.   -- .  Hashed_Mapping_PKG.Is_Empty                        .  SPEC
  7602.   -- .                                                     .
  7603.   -- .......................................................
  7604.   function Is_Empty (Map: MAPPING) return BOOLEAN;
  7605.   --| Purpose
  7606.   --| Return map = {}.
  7607.   --| Raises Uninitialized_Mapping iff map has not been
  7608.   --| initialized.
  7609.   --|
  7610.   --| Exceptions
  7611.   --|   Uninitialized_Mapping
  7612.   --|
  7613.   --| Notes (none)
  7614.  
  7615.   -- .......................................................
  7616.   -- .                                                     .
  7617.   -- .  Hashed_Mapping_PKG.Size                            .  SPEC
  7618.   -- .                                                     .
  7619.   -- .......................................................
  7620.   function Size (Map: MAPPING) return NATURAL;
  7621.   --| Purpose
  7622.   --| Return |map|, the number of bindings in map.
  7623.   --| Raises Uninitialized_Mapping iff map has not been
  7624.   --| initialized.
  7625.   --|
  7626.   --| Exceptions
  7627.   --|   Uninitialized_Mapping
  7628.   --|
  7629.   --| Notes (none)
  7630.  
  7631.   -- .......................................................
  7632.   -- .                                                     .
  7633.   -- .  Hashed_Mapping_PKG.Is_Bound                        .  SPEC
  7634.   -- .                                                     .
  7635.   -- .......................................................
  7636.   function Is_Bound (Map: MAPPING; Key: KEY_TYPE) return BOOLEAN;
  7637.   --| Purpose
  7638.   --| Return true iff equal(key, k) for some <k, v> in map.
  7639.   --| Raises Uninitialized_Mapping iff map has not been
  7640.   --| initialized.
  7641.   --|
  7642.   --| Exceptions
  7643.   --|   Uninitialized_Mapping
  7644.   --|
  7645.   --| Notes (none)
  7646.  
  7647.   -- .......................................................
  7648.   -- .                                                     .
  7649.   -- .  Hashed_Mapping_PKG.Fetch                           .  SPEC
  7650.   -- .                                                     .
  7651.   -- .......................................................
  7652.   function Fetch (Map: MAPPING; Key: KEY_TYPE) return VALUE_TYPE;
  7653.   --| Purpose
  7654.   --| If <k, v>, where equal(key, k), is in map, then return v.
  7655.   --| Raises not_bound if no such <k, v> exists.
  7656.   --| Raises Uninitialized_Mapping iff map has not been
  7657.   --| initialized.
  7658.   --|
  7659.   --| Exceptions
  7660.   --|   Not_Bound
  7661.   --|   Uninitialized_Mapping
  7662.   --|
  7663.   --| Notes (none)
  7664.  
  7665. -- Iterators:
  7666.  
  7667.   -- .......................................................
  7668.   -- .                                                     .
  7669.   -- .  Hashed_Mapping_PKG.Make_Keys_Iter                  .  SPEC
  7670.   -- .                                                     .
  7671.   -- .......................................................
  7672.   function Make_Keys_Iter (Map: MAPPING) return KEYS_ITER;
  7673.   --| Purpose
  7674.   --| Create and return a keys iterator based on map.  This
  7675.   --| object can then be used in conjunction with the more
  7676.   --| function and the next procedure to iterate over all keys
  7677.   --| that are bound in map. Raises Uninitialized_Mapping iff
  7678.   --| map has not been initialized.
  7679.   --|
  7680.   --| Exceptions
  7681.   --|   Uninitialized_Mapping
  7682.   --|
  7683.   --| Notes (none)
  7684.  
  7685.   -- .......................................................
  7686.   -- .                                                     .
  7687.   -- .  Hashed_Mapping_PKG.More                            .  SPEC
  7688.   -- .                                                     .
  7689.   -- .......................................................
  7690.   function More (Iter: KEYS_ITER) return BOOLEAN;
  7691.   --| Purpose
  7692.   --| Return true iff the keys iterator has not been exhausted.
  7693.   --|
  7694.   --| Exceptions (none)
  7695.   --| Notes (none)
  7696.  
  7697.   -- .......................................................
  7698.   -- .                                                     .
  7699.   -- .  Hashed_Mapping_PKG.Next                            .  SPEC
  7700.   -- .                                                     .
  7701.   -- .......................................................
  7702.   procedure Next (Iter: in out KEYS_ITER; Key: out KEY_TYPE);
  7703.   --| Purpose
  7704.   --| Let iter be based on the MAPPING, map.  Successive calls
  7705.   --| of next will return the bound keys of map in some
  7706.   --| arbitrary order. After all bound keys have been returned,
  7707.   --| then the procedure will raise no_more.
  7708.   --|
  7709.   --| Exceptions
  7710.   --|    No_More
  7711.   --|
  7712.   --| Notes
  7713.   --|   Map must not be changed between the invocations of
  7714.   --| Make_Keys_Iterator (Map) and Next.
  7715.       
  7716.   -- .......................................................
  7717.   -- .                                                     .
  7718.   -- .  Hashed_Mapping_PKG.Make_Values_Iter                .  SPEC
  7719.   -- .                                                     .
  7720.   -- .......................................................
  7721.   function Make_Values_Iter (Map: MAPPING) return VALUES_ITER;
  7722.   --| Purpose
  7723.   --| Create and return a values iterator based on map.  This
  7724.   --| object can then be used in conjunction with the more
  7725.   --| function and the next procedure to iterate over all values
  7726.   --| that are bound to keys in map.
  7727.   --| Raises Uninitialized_Mapping iff map has not been
  7728.   --| initialized.
  7729.   --|
  7730.   --| Exceptions
  7731.   --|   Uninitialized_Mapping
  7732.   --|
  7733.   --| Notes (none)
  7734.  
  7735.   -- .......................................................
  7736.   -- .                                                     .
  7737.   -- .  Hashed_Mapping_PKG.More                            .  SPEC
  7738.   -- .                                                     .
  7739.   -- .......................................................
  7740.   function More (Iter: VALUES_ITER) return BOOLEAN;
  7741.   --| Purpose
  7742.   --| Return true iff the values iterator has not been exhausted.
  7743.   --|
  7744.   --| Exceptions (none)
  7745.   --| Notes (none)
  7746.   
  7747.   -- .......................................................
  7748.   -- .                                                     .
  7749.   -- .  Hashed_Mapping_PKG.Next                            .  SPEC
  7750.   -- .                                                     .
  7751.   -- .......................................................
  7752.   procedure Next (Iter: in out VALUES_ITER; Val: out VALUE_TYPE);
  7753.   --| Purpose
  7754.   --| Let iter be based on the MAPPING, map.  Successive calls
  7755.   --| of next will return the bound values of map in some
  7756.   --| arbitrary order. After all bound values have been returned,
  7757.   --| then the procedure will raise no_more.
  7758.   --|
  7759.   --| Exceptions
  7760.   --|   No_More
  7761.   --|
  7762.   --| Notes
  7763.   --|     Map must not be changed between the invocations of
  7764.   --| Make_Values_Iterator (Map) and Next.
  7765.  
  7766.   -- .......................................................
  7767.   -- .                                                     .
  7768.   -- .  Hashed_Mapping_PKG.Make_Keys_Iter                  .  SPEC
  7769.   -- .                                                     .
  7770.   -- .......................................................
  7771.   function Make_Bindings_Iter (Map: MAPPING) return BINDINGS_ITER;
  7772.   --| Purpose
  7773.   --| Create and return a bindings iterator based on map.
  7774.   --| This object can then be used in conjunction with the
  7775.   --| more function and the next procedure to iterate over
  7776.   --| all key/value pairs in map. Raises Uninitialized_Mapping
  7777.   --| iff map has not been initialized.
  7778.   --|
  7779.   --| Exceptions
  7780.   --|   Uninitialized_Mapping
  7781.   --|
  7782.   --| Notes (none)
  7783.  
  7784.   -- .......................................................
  7785.   -- .                                                     .
  7786.   -- .  Hashed_Mapping_PKG.More                            .  SPEC
  7787.   -- .                                                     .
  7788.   -- .......................................................
  7789.   function More (Iter: BINDINGS_ITER) return BOOLEAN;
  7790.   --| Purpose
  7791.   --| Return true iff the bindings iterator has not been exhausted.
  7792.   --|
  7793.   --| Exceptions (none)
  7794.   --| Notes (none)
  7795.     
  7796.   -- .......................................................
  7797.   -- .                                                     .
  7798.   -- .  Hashed_Mapping_PKG.Next                            .  SPEC
  7799.   -- .                                                     .
  7800.   -- .......................................................
  7801.   procedure Next (Iter: in out BINDINGS_ITER;
  7802.           Key:  out    KEY_TYPE;
  7803.           Val:  out    VALUE_TYPE);
  7804.   --| Purpose
  7805.   --| Let iter be based on the MAPPING, map.  Successive calls
  7806.   --| of next will return the key/value pairs of map in some
  7807.   --| arbitrary order. After all such pairs have been returned,
  7808.   --| then the procedure will raise no_more.
  7809.   --|
  7810.   --| Exceptions
  7811.   --|   No_More
  7812.   --|
  7813.   --| Notes
  7814.   --|     Map must not be changed between the invocations of
  7815.   --| Make_Bindings_Iterator (Map) and Next.
  7816.  
  7817. -- Heap management:
  7818.  
  7819.   -- .......................................................
  7820.   -- .                                                     .
  7821.   -- .  Hashed_Mapping_PKG.Destroy                         .  SPEC
  7822.   -- .                                                     .
  7823.   -- .......................................................
  7824.   procedure Destroy (M: in out MAPPING);
  7825.   --| Purpose
  7826.   --| Return space consumed by MAPPING value associated with
  7827.   --| object m to the heap.  (If m is uninitialized, this
  7828.   --| operation does nothing.)  If other objects share the
  7829.   --| same MAPPING value, the further use of these objects is
  7830.   --| erroneous.  COMPONENTs of type VALUE_TYPE, if they are
  7831.   --| access types, are not garbage collected. It is the user's
  7832.   --| responsibility to dispose of these objects. m is left in
  7833.   --| the uninitialized state.
  7834.   --|
  7835.   --| Exceptions (none)
  7836.   --| Notes (none)
  7837.       
  7838. private
  7839.   type COMPONENT is record
  7840.     Key: KEY_TYPE;
  7841.     Val: VALUE_TYPE;
  7842.   end record;
  7843.  
  7844.   function Equal (C1, C2: COMPONENT) return BOOLEAN;
  7845.     -- Return true iff equal(c1.key, c2.key).
  7846.  
  7847.   package Bucket_PKG is new Lists (COMPONENT, Equal);
  7848.   use Bucket_PKG;
  7849.  
  7850.   type BUCKET_ARRAY is array (BUCKET_RANGE) of LIST;
  7851.  
  7852.   type MAPPING_REC is record
  7853.     Size    : NATURAL;
  7854.     Buckets : BUCKET_ARRAY;
  7855.   end record;
  7856.     
  7857.   type MAPPING is access MAPPING_REC;
  7858.   -- Representation Invariants:
  7859.   -- 1. r /= null.  (This would be the uninitialized case)
  7860.   -- 2. If for some i, a COMPONENT, c, is in bucket r.buckets(i),
  7861.   --    then hash(c.key) = i.
  7862.   -- 3. If a COMPONENT, c1, is in bucket, r.buckets(i), then there is
  7863.   --    no other c2 in r.buckets(i) such that equal(c1, c2).
  7864.   --    (Enforce one binding to a given key at any time.)
  7865.   -- 4. r.size equals the total number of COMPONENTs in buckets
  7866.   --    r.buckets(BUCKET_RANGE'first) through
  7867.   --    r.buckets(BUCKET_RANGE'last).
  7868.   --
  7869.   -- Abstraction Function:
  7870.   -- A(r) is the set consisting of all key, value pairs that appear as
  7871.   -- COMPONENTs in buckets r.buckets(BUCKET_RANGE'first) through
  7872.   -- r.buckets(BUCKET_RANGE'last).
  7873.  
  7874.   type GENERAL_ITER is record
  7875.     Map      : MAPPING;
  7876.     Current  : BUCKET_RANGE;
  7877.     Position : LIST;
  7878.   end record;
  7879.  
  7880.   -- For a given general_iter, i, the make, more and next operations
  7881.   -- have the following effects:
  7882.   -- make: Sets map field to the given MAPPING, sets i.current to the
  7883.   -- lowest idx of a nonempty bucket, and sets i.position to the head
  7884.   -- of that bucket.
  7885.   -- more: Returns not empty(i.position).
  7886.   -- next: key, val fields of first COMPONENT of i.position.
  7887.   -- Advances i.position to next COMPONENT in bucket, if it exists.
  7888.   -- Otherwise, increments i.current until a nonempty bucket, and sets
  7889.   -- i.position to this bucket.  When this fails, sets i.position to an
  7890.   -- empty bucket.
  7891.  
  7892.   type KEYS_ITER is new general_iter;
  7893.   type VALUES_ITER is new general_iter;
  7894.   type BINDINGS_ITER is new general_iter;
  7895.  
  7896. end Hashed_Mapping_PKG;
  7897. --::::::::::
  7898. --ltrees.spc
  7899. --::::::::::
  7900. -- *************************************************
  7901. -- *                                               *
  7902. -- *  LABELED_TREES                                *  SPEC
  7903. -- *                                               *
  7904. -- *************************************************
  7905. with Lists;
  7906. generic
  7907.   type LABEL_TYPE is private;
  7908.     -- This is used to identify nodes in the tree.
  7909.   type VALUE_TYPE is private; 
  7910.     -- Information being contained in a node of tree
  7911.   with function "<" (X: in LABEL_TYPE; Y: in LABEL_TYPE)
  7912.       return BOOLEAN is <> ;
  7913.     -- Function which defines ordering of nodes
  7914.     -- a < b -> not (b < a) and  (b /= a) for all a and b.
  7915. package Labeled_Trees is
  7916. --| Purpose
  7917. --| This package creates an ordered binary tree.  This will allow for 
  7918. --| quick insertion, and search.  
  7919. --|
  7920. --| The tree is organized such that 
  7921. --|  
  7922. --|  label (leftchild) < label (root)    label (root) < label (rightchild)
  7923. --| 
  7924. --| This means that by doing a left to right search of the tree will 
  7925. --| produce the nodes of the tree in ascending order.
  7926. --|
  7927. --| Initialization Exceptions (none)
  7928. --| Notes (none)
  7929. --|
  7930. --| Modifications
  7931. --| Author: Bill Toscano and Michael Gordon, Intermetrics, Inc.
  7932.  
  7933.   type TREE is  private;
  7934.   type TREE_ITER is private;
  7935.  
  7936.   Label_Already_Exists_In_Tree : exception;     
  7937.   Label_Not_Present            : exception;
  7938.   No_More                      : exception;
  7939.   Tree_Is_Empty                : exception;    
  7940.  
  7941.   -- ....................................................
  7942.   -- .                                                  .
  7943.   -- .  LABELED_TREES.CREATE                            .  SPEC
  7944.   -- .                                                  .
  7945.   -- ....................................................
  7946.   function Create return TREE;
  7947.   --| Purpose
  7948.   --| This creates a tree containing no information and no children.  An 
  7949.   --| emptytree.
  7950.   --|
  7951.   --| Exceptions (none)
  7952.   --| Notes (none)
  7953.  
  7954.   -- ....................................................
  7955.   -- .                                                  .
  7956.   -- .  LABELED_TREES.DESTROY_DEEP_TREE                 .  SPEC
  7957.   -- .                                                  .
  7958.   -- ....................................................
  7959.   generic
  7960.     with procedure Dispose_Label (L :in out LABEL_TYPE);
  7961.     with procedure Dispose_Value (V :in out VALUE_TYPE);
  7962.   procedure Destroy_Deep_Tree (T : in out TREE);
  7963.   --| Purpose
  7964.   --| Destroys all nodes in a tree and the label and value associated
  7965.   --| with each node.
  7966.   --|
  7967.   --| Exceptions (none)
  7968.   --| Notes (none)
  7969.     
  7970.   -- ....................................................
  7971.   -- .                                                  .
  7972.   -- .  LABELED_TREES.DESTROY_TREE                      .  SPEC
  7973.   -- .                                                  .
  7974.   -- ....................................................
  7975.   procedure Destroy_Tree (T : in out TREE);
  7976.   --| Purpose
  7977.   --| Destroys a tree and returns the space which it is occupying.
  7978.   --|
  7979.   --| Exceptions (none)
  7980.   --| Notes (none)
  7981.  
  7982.   -- ....................................................
  7983.   -- .                                                  .
  7984.   -- .  LABELED_TREES.FETCH_VALUE                       .  SPEC
  7985.   -- .                                                  .
  7986.   -- ....................................................
  7987.   function Fetch_Value (T : in TREE;
  7988.                         L : in LABEL_TYPE) return VALUE_TYPE;   
  7989.   --| Purpose
  7990.   --| Get the value of the node with the given label.
  7991.   --| If the label is not present Label_Not_Present is raised.
  7992.   --|
  7993.   --| Exceptions
  7994.   --|   Label_Not_Present
  7995.   --|
  7996.   --| Notes (none)
  7997.  
  7998.   -- ....................................................
  7999.   -- .                                                  .
  8000.   -- .  LABELED_TREES.FETCH_VALUE                       .  SPEC
  8001.   -- .                                                  .
  8002.   -- ....................................................
  8003.   function Fetch_Value (T : in TREE) return VALUE_TYPE;
  8004.   --| Purpose
  8005.   --| Return the value stored at the root node of the given tree.
  8006.   --| Raises Label_Not_Present if the tree T is empty.  
  8007.   --|
  8008.   --| Exceptions
  8009.   --|   Label_Not_Present
  8010.   --|
  8011.   --| Notes (none)
  8012.  
  8013.   -- ....................................................
  8014.   -- .                                                  .
  8015.   -- .  LABELED_TREES.GET_TREE                          .  SPEC
  8016.   -- .                                                  .
  8017.   -- ....................................................
  8018.   function Get_Tree (T : in TREE;
  8019.                      L : in LABEL_TYPE) return TREE;
  8020.   --| Purpose
  8021.   --| Get the subtree whose root is labelled L.
  8022.   --|
  8023.   --| Exceptions
  8024.   --|   Label_Not_Present if the label L is not in T
  8025.   --|
  8026.   --| Notes (none)
  8027.  
  8028.   -- ....................................................
  8029.   -- .                                                  .
  8030.   -- .  LABELED_TREES.FORWARD                           .  SPEC
  8031.   -- .                                                  .
  8032.   -- ....................................................
  8033.   procedure Forward (I : in out TREE_ITER);
  8034.   --| Purpose
  8035.   --| This is used to advance the iterator.  Typically this is used in
  8036.   --| conjunction with Node_Value and Node_Label.
  8037.   --|
  8038.   --| Exceptions (none)
  8039.   --| Notes (none)
  8040.  
  8041.   -- ....................................................
  8042.   -- .                                                  .
  8043.   -- .  LABELED_TREES.INSERT_NODE                       .  SPEC
  8044.   -- .                                                  .
  8045.   -- ....................................................
  8046.   procedure Insert_Node (T : in out TREE;
  8047.                          L : in LABEL_TYPE;
  8048.                          V : in VALUE_TYPE);
  8049.   --| Purpose
  8050.   --| Inserts a node into the specified tree.
  8051.   --| This adds the node with label L to the tree T.  Label_Already_Exists is 
  8052.   --| raised if L already exists in T.
  8053.   --|
  8054.   --| Exceptions
  8055.   --|   Label_Already_Exists
  8056.   --|
  8057.   --| Notes (none)
  8058.  
  8059.   -- ....................................................
  8060.   -- .                                                  .
  8061.   -- .  LABELED_TREES.IS_EMPTY                          .  SPEC
  8062.   -- .                                                  .
  8063.   -- ....................................................
  8064.   function Is_Empty (T : in TREE) return BOOLEAN;
  8065.   --| Purpose
  8066.   --| Returns TRUE iff the tree is empty.
  8067.   --|
  8068.   --| Exceptions (none)
  8069.   --| Notes (none)
  8070.  
  8071.   -- ....................................................
  8072.   -- .                                                  .
  8073.   -- .  LABELED_TREES.IS_LABEL_IN_TREE                  .  SPEC
  8074.   -- .                                                  .
  8075.   -- ....................................................
  8076.   function Is_Label_In_Tree (T : in TREE;
  8077.                              L : in LABEL_TYPE) return BOOLEAN;
  8078.   --| Purpose
  8079.   --| Returns TRUE iff the given labels is in the given tree.
  8080.   --|
  8081.   --| Exceptions (none)
  8082.   --| Notes (none)
  8083.  
  8084.   -- ....................................................
  8085.   -- .                                                  .
  8086.   -- .  LABELED_TREES.IS_LABEL_IN_TREE                  .  SPEC
  8087.   -- .                                                  .
  8088.   -- ....................................................
  8089.   procedure Is_Label_In_Tree (T       : in TREE;
  8090.                               L       : in LABEL_TYPE;
  8091.                               Subtree : out TREE;
  8092.                               Present : out BOOLEAN);
  8093.   --| Purpose
  8094.   --| This operation can be used to see if a label is in the tree.
  8095.   --| It sets the variable Present to TRUE iff the given label is in
  8096.   --| the given tree.
  8097.   --| If it is, the Subtree out parameter can then be used to
  8098.   --| to update the value field of the label.  The sequence would be
  8099.   --| 
  8100.   --|  Is_Label_In_Tree (T, L, Subtree, Present);
  8101.   --|  if Present then
  8102.   --|     Store_Value (Subtree, SomeValue);
  8103.   --|  end if;
  8104.   --| 
  8105.   --| If the label is not Present, then Subtree is the root of the tree
  8106.   --| where the label would be stored if it were present.  Thus the following
  8107.   --| sequence would be useful.
  8108.   --|
  8109.   --| Is_Label_In_Tree (T, L, Subtree, Present);
  8110.   --| if not Present then
  8111.   --|    Insert_Node (Subtree, L, V);
  8112.   --| end if;
  8113.   --| 
  8114.   --| The advantage to this routine is that the tree need only be searched 
  8115.   --| once instead of twice once for the existence check and then once for
  8116.   --| the insertion.
  8117.   --|
  8118.   --| Exceptions (none)
  8119.   --| Notes (none)
  8120.  
  8121.   -- ....................................................
  8122.   -- .                                                  .
  8123.   -- .  LABELED_TREES.ITERATOR_LABEL                    .  SPEC
  8124.   -- .                                                  .
  8125.   -- ....................................................
  8126.   function Iterator_Label (I : in TREE_ITER) return LABEL_TYPE;
  8127.   --| Purpose
  8128.   --| Returns the label of the node corresponding to the iterator.
  8129.   --|
  8130.   --| Exceptions (none)
  8131.   --| Notes (none)
  8132.  
  8133.   -- ....................................................
  8134.   -- .                                                  .
  8135.   -- .  LABELED_TREES.ITERATOR_VALUE                    .  SPEC
  8136.   -- .                                                  .
  8137.   -- ....................................................
  8138.   function Iterator_Value (I : in TREE_ITER) return VALUE_TYPE;
  8139.   --| Purpose
  8140.   --| Returns the value of the node corresponding to the iterator.
  8141.   --|
  8142.   --| Exceptions (none)
  8143.   --| Notes (none)
  8144.  
  8145.   -- ....................................................
  8146.   -- .                                                  .
  8147.   -- .  LABELED_TREES.MAKE_TREE                         .  SPEC
  8148.   -- .                                                  .
  8149.   -- ....................................................
  8150.   function Make_Tree (L : in LABEL_TYPE;
  8151.                       V : in VALUE_TYPE) return TREE;
  8152.   --| Purpose
  8153.   --| Creates a tree whose root has the given label and value.
  8154.   --|
  8155.   --| Exceptions (none)
  8156.   --| Notes (none)
  8157.  
  8158.   -- ....................................................
  8159.   -- .                                                  .
  8160.   -- .  LABELED_TREES.MAKE_TREE_ITER_IN                 .  SPEC
  8161.   -- .                                                  .
  8162.   -- ....................................................
  8163.   function Make_Tree_Iter_In  (T : in TREE) return TREE_ITER;
  8164.   --| Purpose
  8165.   --| This sets up an iteration of the nodes of the tree in inorder.
  8166.   --| By using the Next operations the nodes of the tree are returned in
  8167.   --| in inorder. Inorder means return the left child then the node 
  8168.   --| then the right child.
  8169.   --|
  8170.   --| Exceptions (none)
  8171.   --| Notes (none)
  8172.  
  8173.   -- ....................................................
  8174.   -- .                                                  .
  8175.   -- .  LABELED_TREES.MAKE_TREE_ITER_POST               .  SPEC
  8176.   -- .                                                  .
  8177.   -- ....................................................
  8178.   function Make_Tree_Iter_Post (T : in TREE) return TREE_ITER;
  8179.   --| Purpose
  8180.   --| This sets up an iteration of the nodes of the tree in postorder.
  8181.   --| By using the Next operations the nodes of the tree are returned in
  8182.   --| post order. Post order means return the node first then its left child 
  8183.   --| and then its right child.
  8184.   --|
  8185.   --| Exceptions (none)
  8186.   --| Notes (none)
  8187.  
  8188.   -- ....................................................
  8189.   -- .                                                  .
  8190.   -- .  LABELED_TREES.MAKE_TREE_ITER_PRE                .  SPEC
  8191.   -- .                                                  .
  8192.   -- ....................................................
  8193.   function Make_Tree_Iter_Pre (T : in TREE) return TREE_ITER;
  8194.   --| Purpose
  8195.   --| This sets up an iteration of the nodes of the tree in preorder.
  8196.   --| By using the Next operations the nodes of the tree are returned in
  8197.   --| ascending order.
  8198.   --|
  8199.   --| Exceptions (none)
  8200.   --| Notes (none)
  8201.  
  8202.   -- ....................................................
  8203.   -- .                                                  .
  8204.   -- .  LABELED_TREES.MORE                              .  SPEC
  8205.   -- .                                                  .
  8206.   -- ....................................................
  8207.   function More (I : in TREE_ITER) return BOOLEAN;
  8208.   --| Purpose
  8209.   --| Returns TRUE iff there are more elements in the tree to
  8210.   --| iterate over.
  8211.   --|
  8212.   --| Exceptions (none)
  8213.   --| Notes (none)
  8214.  
  8215.   -- ....................................................
  8216.   -- .                                                  .
  8217.   -- .  LABELED_TREES.NEXT                              .  SPEC
  8218.   -- .                                                  .
  8219.   -- ....................................................
  8220.   procedure Next (I : in out TREE_ITER;
  8221.                   V : out VALUE_TYPE);    
  8222.   --| Purpose
  8223.   --| This returns the next element in the iteration and advances the iterator.
  8224.   --| No_More is raised when after the last element has been returned and
  8225.   --| an attempt is made to get another element.
  8226.   --|
  8227.   --| Exceptions
  8228.   --|   No_More
  8229.   --|
  8230.   --| Notes (none)
  8231.  
  8232.   -- ....................................................
  8233.   -- .                                                  .
  8234.   -- .  LABELED_TREES.NEXT                              .  SPEC
  8235.   -- .                                                  .
  8236.   -- ....................................................
  8237.   procedure Next (I : in out TREE_ITER;
  8238.                   V : out VALUE_TYPE;
  8239.                   L : out LABEL_TYPE);    
  8240.   --| Purpose
  8241.   --| This iteration operation returns the label of a node as well as the 
  8242.   --| node's value.  No_More is raised if Next is called after the last
  8243.   --| element of the tree has been returned.
  8244.   --|
  8245.   --| Exceptions
  8246.   --|   No_More
  8247.   --|
  8248.   --| Notes (none)
  8249.  
  8250.   -- ....................................................
  8251.   -- .                                                  .
  8252.   -- .  LABELED_TREES.STORE_VALUE                       .  SPEC
  8253.   -- .                                                  .
  8254.   -- ....................................................
  8255.   procedure Store_Value (T : in out TREE;
  8256.                          L : in LABEL_TYPE;
  8257.                          V : in VALUE_TYPE);
  8258.   --| Purpose
  8259.   --| Sets a new value V in the tree T at the node identified
  8260.   --| by the label L.  
  8261.   --| Label_Not_Present is raised if L is not in T.
  8262.   --|
  8263.   --| Exceptions
  8264.   --|   Label_Not_Present
  8265.   --|
  8266.   --| Notes (none)
  8267.  
  8268.   -- ....................................................
  8269.   -- .                                                  .
  8270.   -- .  LABELED_TREES.STORE_VALUE                       .  SPEC
  8271.   -- .                                                  .
  8272.   -- ....................................................
  8273.   procedure Store_Value (T : in out TREE;
  8274.                          V : in VALUE_TYPE);
  8275.   --| Purpose
  8276.   --| This stores the value V in the root node of the tree T.   
  8277.   --| Raises Label_Not_Present if T is empty.
  8278.   --|
  8279.   --| Exceptions
  8280.   --|   Label_Not_Present
  8281.   --|
  8282.   --| Notes (none)
  8283.  
  8284. private
  8285.    type NODE;
  8286.    type TREE is access NODE;
  8287.  
  8288.    type NODE is 
  8289.      record
  8290.        Label       : LABEL_TYPE;
  8291.        Value       : VALUE_TYPE;
  8292.        Left_Child  : TREE;
  8293.        Right_Child : TREE;
  8294.      end record;
  8295.  
  8296.    package NODE_ORDER is new Lists (TREE);
  8297.  
  8298.    type TREE_ITER is
  8299.       record
  8300.         Node_List : Node_Order.LIST;
  8301.         State     : Node_Order.LISTITER;
  8302.       end record;
  8303.  
  8304. end Labeled_Trees;
  8305. --::::::::::
  8306. --set.spc
  8307. --::::::::::
  8308. -- ************************************************
  8309. -- *                                              *
  8310. -- *  SET_PKG                                     *  SPEC
  8311. -- *                                              *
  8312. -- ************************************************
  8313. with Lists;
  8314. pragma Elaborate (Lists);
  8315. generic
  8316.     type ELEM_TYPE is private;
  8317.     with function Equal (E1, E2: ELEM_TYPE) return BOOLEAN is "=";
  8318. package Set_Pkg is
  8319. --| Purpose
  8320. --| This package provides the set abstract data type.  All standard set
  8321. --| operations are provided.  Standard mathematical set notation is
  8322. --| employed to describe the effects of the operations.
  8323. --|
  8324. --| The component type, and an equality relation used for membership
  8325. --| tests, are generic formals of the package. The implementation isn't
  8326. --| particularly fast, since the only available information about the
  8327. --| component type is the equality relation. However, this shouldn't be a
  8328. --| concern unless the sets become large or speed becomes important.
  8329. --| See scalar_set_pkg, hashed_set_pkg and ordered_set_pkg for other
  8330. --| implementations.
  8331. --|
  8332. --| Initialization Exceptions (none)
  8333. --| Notes (none)
  8334. --|
  8335. --| Modifications
  8336. --| Programmer: Ron Kownacki, Intermetrics
  8337. --| One of a family of set packages:
  8338.  
  8339.     type SET is private;
  8340.  
  8341. -- Exceptions:
  8342.  
  8343.     No_More: exception;       -- Raised on incorrect use of an iterator.
  8344.  
  8345. -- Iterators:
  8346.   
  8347.     type MEMBERS_ITER is private;  -- Members of a set in arbitrary order
  8348.  
  8349. -- Constructors:
  8350.  
  8351.   -- ...............................................
  8352.   -- .                                             .
  8353.   -- .  SET_PKG.CREATE                             .  SPEC
  8354.   -- .                                             .
  8355.   -- ...............................................
  8356.   function Create return SET;
  8357.   --| Purpose
  8358.   --| Return {}.  This operation is not strictly necessary, since an
  8359.   --| uninitialized set object is viewed as the empty set.
  8360.   --|
  8361.   --| Exceptions (none)
  8362.   --| Notes (none)
  8363.  
  8364.   -- ...............................................
  8365.   -- .                                             .
  8366.   -- .  SET_PKG.INSERT                             .  SPEC
  8367.   -- .                                             .
  8368.   -- ...............................................
  8369.   procedure Insert (S: in out SET;
  8370.                     E: in     ELEM_TYPE);
  8371.   --| Purpose
  8372.   --| Insert the element, e, into the set, s.
  8373.   --|
  8374.   --| Exceptions (none)
  8375.   --| Notes (none)
  8376.  
  8377.   -- ...............................................
  8378.   -- .                                             .
  8379.   -- .  SET_PKG.DELETE                             .  SPEC
  8380.   -- .                                             .
  8381.   -- ...............................................
  8382.   procedure Delete (S: in out SET;
  8383.                     E: in     ELEM_TYPE);
  8384.   --| Purpose
  8385.   --| If e is in s, then remove e from s.  Otherwise, no effect.
  8386.   --|
  8387.   --| Exceptions (none)
  8388.   --| Notes (none)
  8389.       
  8390.   -- ...............................................
  8391.   -- .                                             .
  8392.   -- .  SET_PKG.INTERSECT                          .  SPEC
  8393.   -- .                                             .
  8394.   -- ...............................................
  8395.   function Intersect (S1, S2: SET) return SET;
  8396.   --| Purpose
  8397.   --| Return {e | member(s1, e) and member(s2, e)}.
  8398.   --|
  8399.   --| Exceptions (none)
  8400.   --| Notes (none)
  8401.       
  8402.   -- ...............................................
  8403.   -- .                                             .
  8404.   -- .  SET_PKG.UNION                              .  SPEC
  8405.   -- .                                             .
  8406.   -- ...............................................
  8407.   function Union (S1, S2: SET) return SET;
  8408.   --| Purpose
  8409.   --| Return {e | member(s1, e) or member(s2, e)}.
  8410.   --|
  8411.   --| Exceptions (none)
  8412.   --| Notes (none)
  8413.  
  8414.   -- ...............................................
  8415.   -- .                                             .
  8416.   -- .  SET_PKG.COPY                               .  SPEC
  8417.   -- .                                             .
  8418.   -- ...............................................
  8419.   function Copy (S: SET) return SET;
  8420.   --| Purpose
  8421.   --| Returns a copy of s.  Subsequent changes to s will not be
  8422.   --| visible through the application of operations to the copy of s.
  8423.   --| Assignment or parameter passing without copying will result
  8424.   --| in a single set value being shared among objects.
  8425.   --| The assignment operation is used to transfer the values of
  8426.   --| the elem_type components of s; consequently, changes in these
  8427.   --| values may be observable through both sets if these types are
  8428.   --| access types, or if they contain access type components.
  8429.   --|
  8430.   --| Exceptions (none)
  8431.   --| Notes (none)
  8432.   
  8433. -- Query Operations
  8434.  
  8435.   -- ...............................................
  8436.   -- .                                             .
  8437.   -- .  SET_PKG.EQUAL                              .  SPEC
  8438.   -- .                                             .
  8439.   -- ...............................................
  8440.   function Equal (S1, S2: SET) return BOOLEAN;
  8441.   --| Purpose
  8442.   --| Return (for all e: elem_type (member(s1, e) iff member(s2, e))).
  8443.   --| Note that (s1 = s2) implies equal(s1, s2) holds for all time.
  8444.   --| "=" is object equality, equal is state equality.
  8445.   --|
  8446.   --| Exceptions (none)
  8447.   --| Notes (none)
  8448.  
  8449.   -- ...............................................
  8450.   -- .                                             .
  8451.   -- .  SET_PKG.IS_EMPTY                           .  SPEC
  8452.   -- .                                             .
  8453.   -- ...............................................
  8454.   function Is_Empty (S: SET) return BOOLEAN;
  8455.   --| Purpose
  8456.   --| Return s = {}.
  8457.   --|
  8458.   --| Exceptions (none)
  8459.   --| Notes (none)
  8460.  
  8461.   -- ...............................................
  8462.   -- .                                             .
  8463.   -- .  SET_PKG.IS_MEMBER                          .  SPEC
  8464.   -- .                                             .
  8465.   -- ...............................................
  8466.   function Is_Member (S: SET; E: ELEM_TYPE) return BOOLEAN;
  8467.   --| Purpose
  8468.   --| Return true iff e is a member of s.
  8469.   --|
  8470.   --| Exceptions (none)
  8471.   --| Notes (none)
  8472.  
  8473.   -- ...............................................
  8474.   -- .                                             .
  8475.   -- .  SET_PKG.SIZE                               .  SPEC
  8476.   -- .                                             .
  8477.   -- ...............................................
  8478.   function Size (S: SET) return NATURAL;
  8479.   --| Purpose
  8480.   --| Return |s|, the cardinality of s.
  8481.   --|
  8482.   --| Exceptions (none)
  8483.   --| Notes (none)
  8484.  
  8485. -- Iterators
  8486.  
  8487.   -- ...............................................
  8488.   -- .                                             .
  8489.   -- .  SET_PKG.MAKE_MEMBERS_ITER                  .  SPEC
  8490.   -- .                                             .
  8491.   -- ...............................................
  8492.   function Make_Members_Iter (S: SET) return MEMBERS_ITER;
  8493.   --| Purpose
  8494.   --| Create and return a members iterator based on s.  This object
  8495.   --| can then be used in conjunction with the more function and the
  8496.   --| next procedure to iterate over the members of s in some
  8497.   --| arbitrary order.
  8498.   --|
  8499.   --| Exceptions (none)
  8500.   --| Notes (none)
  8501.  
  8502.   -- ...............................................
  8503.   -- .                                             .
  8504.   -- .  SET_PKG.MORE                               .  SPEC
  8505.   -- .                                             .
  8506.   -- ...............................................
  8507.   function More (Iter: MEMBERS_ITER) return BOOLEAN;
  8508.   --| Purpose
  8509.   --| Return true iff the members iterator has not been exhausted.
  8510.   --|
  8511.   --| Exceptions (none)
  8512.   --| Notes (none)
  8513.  
  8514.   -- ...............................................
  8515.   -- .                                             .
  8516.   -- .  SET_PKG.NEXT                               .  SPEC
  8517.   -- .                                             .
  8518.   -- ...............................................
  8519.   procedure Next (Iter: in out MEMBERS_ITER;
  8520.                   E:    out    ELEM_TYPE);
  8521.   --| Purpose
  8522.   --| Let iter be based on the set, s.  Successive calls of next
  8523.   --| will return the members of s in some arbitrary order.
  8524.   --| After all members have been returned, then the procedure will
  8525.   --| raise no_more.
  8526.   --| Requires:
  8527.   --| s must not be changed between the invocations of
  8528.   --| make_nodes_iterator(g) and next.
  8529.   --|
  8530.   --| Exceptions
  8531.   --|   no_more
  8532.   --|
  8533.   --| Notes (none)
  8534.  
  8535. -- Heap management
  8536.  
  8537.   -- ...............................................
  8538.   -- .                                             .
  8539.   -- .  SET_PKG.DESTROY                            .  SPEC
  8540.   -- .                                             .
  8541.   -- ...............................................
  8542.   procedure Destroy (S: in out SET);
  8543.   --| Purpose
  8544.   --| Return space consumed by the set value associated with object
  8545.   --| s to the heap.  If other objects share the same set value, then
  8546.   --| further use of these objects is erroneous.  Components of type
  8547.   --| elem_type, if they are access types, are not garbage collected.
  8548.   --| It is the user's responsibility to dispose of these objects.
  8549.   --| s is set to {}.
  8550.   --|
  8551.   --| Exceptions (none)
  8552.   --| Notes (none)
  8553.  
  8554. private
  8555.     package List_Pkg is new Lists (ELEM_TYPE, Equal);
  8556.     use List_Pkg;
  8557.     
  8558.     type SET is new LIST;
  8559.  
  8560.       -- Representation Invariants:
  8561.       --   None; all lists are legal representations of sets.
  8562.       -- Abstraction Function:  A: representation --> set
  8563.       --   A(null) = create.
  8564.       --   A(attach(r, e)) = insert(A(r), e).
  8565.       --   Sufficient since all lists can be generated by null, attach.
  8566.       --
  8567.       --     Note that this implementation allows faster insertion and
  8568.       -- membership testing than if duplicate insertions of an element
  8569.       -- caused a check to ensure that each element is only kept once in
  8570.       -- the list.  This implies that deleting an element always involves
  8571.       -- a scan of the entire list.
  8572.     
  8573.     type MEMBERS_ITER is new LIST;
  8574.  
  8575.       -- For a set, s, make returns members_iter(copy(list(s))).
  8576.       -- More(iter) returns true iff list(iter) isn't empty.
  8577.       -- Next(iter) returns the first element in list(iter).  Before doing 
  8578.       -- this, it removes all occurrences of this element from list(iter).
  8579.  
  8580. end Set_Pkg;
  8581. --::::::::::
  8582. --stack.spc
  8583. --::::::::::
  8584. -- **************************************************
  8585. -- *                                                *
  8586. -- *  STACK_PKG                                     *  SPEC
  8587. -- *                                                *
  8588. -- **************************************************
  8589. with Lists;
  8590. generic
  8591.     type ELEM_TYPE is private;
  8592. package Stack_Pkg is
  8593. --| Purpose
  8594. --| This package provides the stack abstract data type.  Element type is
  8595. --| a generic formal parameter to the package.  There are no explicit
  8596. --| bounds on the number of objects that can be pushed onto a given stack.
  8597. --| All standard stack operations are provided.
  8598. --|
  8599. --| Initialization Exceptions (none)
  8600. --| Notes (none)
  8601. --|
  8602. --| Modifications
  8603. --| Programmer: Ron Kownacki, Intermetrics
  8604.  
  8605.     type STACK is private;
  8606.     
  8607. -- Exceptions:
  8608.   
  8609.     Uninitialized_Stack: exception;
  8610.         -- Raised on attempt to manipulate an uninitialized stack object.
  8611.         -- The initialization operations are create and copy.
  8612.  
  8613.     Empty_Stack: exception;
  8614.         -- Raised by some operations when empty.
  8615.  
  8616. -- Constructors:
  8617.  
  8618.   -- ..............................................................
  8619.   -- .                                                            .
  8620.   -- .  STACK_PKG.CREATE                                          .  SPEC
  8621.   -- .                                                            .
  8622.   -- ..............................................................
  8623.   function Create return STACK;
  8624.   --| Purpose
  8625.   --| Return the empty stack.
  8626.   --|
  8627.   --| Exceptions (none)
  8628.   --| Notes (none)
  8629.  
  8630.   -- ..............................................................
  8631.   -- .                                                            .
  8632.   -- .  STACK_PKG.PUSH                                            .  SPEC
  8633.   -- .                                                            .
  8634.   -- ..............................................................
  8635.   procedure Push (S: in out STACK; E: in ELEM_TYPE);
  8636.   --| Purpose
  8637.   --| Push e onto the top of s.
  8638.   --| Raises uninitialized_stack iff s has not been initialized.
  8639.   --|
  8640.   --| Exceptions
  8641.   --|   uninitialized_stack
  8642.   --|
  8643.   --| Notes (none)
  8644.  
  8645.   -- ..............................................................
  8646.   -- .                                                            .
  8647.   -- .  STACK_PKG.POP                                             .  SPEC
  8648.   -- .                                                            .
  8649.   -- ..............................................................
  8650.   procedure Pop (S: in out STACK);
  8651.   --| Purpose
  8652.   --| Pops the top element from s, and throws it away.
  8653.   --| Raises empty_stack iff s is empty.
  8654.   --| Raises uninitialized_stack iff s has not been initialized.
  8655.   --|
  8656.   --| Exceptions
  8657.   --|   empty_stack
  8658.   --|   uninitialized_stack
  8659.   --|
  8660.   --| Notes (none)
  8661.  
  8662.   -- ..............................................................
  8663.   -- .                                                            .
  8664.   -- .  STACK_PKG.POP                                             .  SPEC
  8665.   -- .                                                            .
  8666.   -- ..............................................................
  8667.   procedure Pop (S: in out STACK; E: out ELEM_TYPE);
  8668.   --| Purpose
  8669.   --| Pops the top element from s, returns it as the e parameter.
  8670.   --| Raises empty_stack iff s is empty.
  8671.   --| Raises uninitialized_stack iff s has not been initialized.
  8672.   --|
  8673.   --| Exceptions
  8674.   --|   empty_stack
  8675.   --|   uninitialized_stack
  8676.   --|
  8677.   --| Notes (none)
  8678.       
  8679.   -- ..............................................................
  8680.   -- .                                                            .
  8681.   -- .  STACK_PKG.COPY                                            .  SPEC
  8682.   -- .                                                            .
  8683.   -- ..............................................................
  8684.   function Copy (S: STACK) return STACK;
  8685.   --| Purpose
  8686.   --| Return a copy of s.
  8687.   --| Stack assignment and passing stacks as subprogram parameters
  8688.   --| result in the sharing of a single stack value by two stack
  8689.   --| objects; changes to one will be visible through the others.
  8690.   --| copy can be used to prevent this sharing.
  8691.   --| Raises uninitialized_stack iff s has not been initialized.
  8692.   --|
  8693.   --| Exceptions
  8694.   --|   uninitialized_stack
  8695.   --|
  8696.   --| Notes (none)
  8697.       
  8698. -- Queries:
  8699.  
  8700.   -- ..............................................................
  8701.   -- .                                                            .
  8702.   -- .  STACK_PKG.TOP                                             .  SPEC
  8703.   -- .                                                            .
  8704.   -- ..............................................................
  8705.   function Top (S: STACK) return ELEM_TYPE;
  8706.   --| Purpose
  8707.   --| Return the element on the top of s.  Raises empty_stack iff s is
  8708.   --| empty.
  8709.   --| Raises uninitialized_stack iff s has not been initialized.
  8710.   --|
  8711.   --| Exceptions
  8712.   --|   empty_stack
  8713.   --|   uninitialized_stack
  8714.   --|
  8715.   --| Notes (none)
  8716.       
  8717.   -- ..............................................................
  8718.   -- .                                                            .
  8719.   -- .  STACK_PKG.SIZE                                            .  SPEC
  8720.   -- .                                                            .
  8721.   -- ..............................................................
  8722.   function Size (S: STACK) return NATURAL;
  8723.   --| Purpose
  8724.   --| Return the current number of elements in s.
  8725.   --| Raises uninitialized_stack iff s has not been initialized.
  8726.   --|
  8727.   --| Exceptions
  8728.   --|   uninitialized_stack
  8729.   --|
  8730.   --| Notes (none)
  8731.  
  8732.   -- ..............................................................
  8733.   -- .                                                            .
  8734.   -- .  STACK_PKG.IS_EMPTY                                        .  SPEC
  8735.   -- .                                                            .
  8736.   -- ..............................................................
  8737.   function Is_Empty (S: STACK) return BOOLEAN;
  8738.   --| Purpose
  8739.   --| Return true iff s is empty.
  8740.   --| Raises uninitialized_stack iff s has not been initialized.
  8741.   --|
  8742.   --| Exceptions
  8743.   --|   uninitialized_stack
  8744.   --|
  8745.   --| Notes (none)
  8746.  
  8747. -- Heap Management:
  8748.  
  8749.   -- ..............................................................
  8750.   -- .                                                            .
  8751.   -- .  STACK_PKG.DESTROY                                         .  SPEC
  8752.   -- .                                                            .
  8753.   -- ..............................................................
  8754.   procedure Destroy (S: in out STACK);
  8755.   --| Purpose
  8756.   --| Return the space consumed by s to the heap.  No effect if s is
  8757.   --| uninitialized.  In any case, leaves s in uninitialized state.
  8758.   --|
  8759.   --| Exceptions (none)
  8760.   --| Notes (none)
  8761.  
  8762. private
  8763.     package Elem_List_Pkg is new Lists (ELEM_TYPE);
  8764.     subtype ELEM_LIST is Elem_List_Pkg.LIST;
  8765.  
  8766.     type STACK_REC is
  8767.         record
  8768.             Size: NATURAL := 0;
  8769.             Elts: ELEM_LIST := Elem_List_Pkg.Create;
  8770.         end record;
  8771.     type STACK is access STACK_REC;
  8772.     -- Let an instance of the representation type, r, be denoted by the
  8773.     -- pair, <size, elts>.  Dot selection is used to refer to these
  8774.     -- components.
  8775.     --
  8776.     -- Representation Invariants:
  8777.     --     r /= null
  8778.     --     elem_list_pkg.length(r.elts) = r.size.
  8779.     --
  8780.     -- Abstraction Function:
  8781.     --     A(<size, elem_list_pkg.create>) = stack_pkg.create.
  8782.     --     A(<size, elem_list_pkg.attach(e, l)>) = push(A(<size, l>), e).
  8783.  
  8784. end Stack_Pkg;
  8785. --::::::::::
  8786. --clp.spc
  8787. --::::::::::
  8788. -- **********************************************
  8789. -- *                                            *
  8790. -- * COMMAND_LINE_PROCESSOR (CLP)               * SPEC
  8791. -- *                                            *
  8792. -- **********************************************
  8793. package Command_Line_Processor is
  8794. --| Purpose
  8795. --|   COMMAND_LINE_PROCESSOR is an abstract state machine
  8796. --| that allows the user to access a command line, which
  8797. --| may contain file references which are include files,
  8798. --| as a simple list of file names which can be accessed
  8799. --| via an interator and a Get function.  The command line
  8800. --| syntax is:
  8801. --|
  8802. --|      command input_file input_file ... output_file
  8803. --| or:
  8804. --|      command input_file input_file ... input_file
  8805. --|
  8806. --| where any "input_file" may be prefixed by an "@"
  8807. --| to make it an include file.
  8808. --|
  8809. --| Initialization Exceptions (none)
  8810. --| Notes (none)
  8811. --| Modifications
  8812. --|   2/19/90  Rick Conn  Initial Design and Code
  8813.  
  8814.   type COMMAND_LINE_LAYOUT is (ALL_INPUT_FILES,
  8815.                                ONE_OUTPUT_FILE);
  8816.   -- the command line either contains only input
  8817.   -- files or a group of input files and one
  8818.   -- output file
  8819.  
  8820.   -- ..............................................
  8821.   -- .                                            .
  8822.   -- . CLP.INITIALIZE                             . SPEC
  8823.   -- .                                            .
  8824.   -- ..............................................
  8825.   procedure Initialize (Program_Name : in STRING;
  8826.                         Command_Kind : in COMMAND_LINE_LAYOUT
  8827.                                        := ONE_OUTPUT_FILE);
  8828.   --| Purpose
  8829.   --| Initialize the package, specifying a program
  8830.   --| name which may be used by the Command Line
  8831.   --| Interface
  8832.   --|
  8833.   --| Exceptions
  8834.   --|   ALLOCATION_PROBLEM
  8835.   --|   INIT_ERROR
  8836.   --|
  8837.   --| Notes
  8838.   --|   CALL INITIALIZE ONLY ONCE
  8839.  
  8840.   -- ..............................................
  8841.   -- .                                            .
  8842.   -- . CLP.RESET                                  . SPEC
  8843.   -- .                                            .
  8844.   -- ..............................................
  8845.   procedure Reset;
  8846.   --| Purpose
  8847.   --| Reset the iterator.
  8848.   --|
  8849.   --| Exceptions (none)
  8850.   --| Notes (none)
  8851.  
  8852.   -- ..............................................
  8853.   -- .                                            .
  8854.   -- . CLP.IS_END                                 . SPEC
  8855.   -- .                                            .
  8856.   -- ..............................................
  8857.   function Is_End return BOOLEAN;
  8858.   --| Purpose
  8859.   --| Return TRUE if no more file names are
  8860.   --| available.
  8861.   --|
  8862.   --| Exceptions (none)
  8863.   --| Notes (none)
  8864.  
  8865.   -- ..............................................
  8866.   -- .                                            .
  8867.   -- . CLP.FILE_NAME                              . SPEC
  8868.   -- .                                            .
  8869.   -- ..............................................
  8870.   function File_Name return STRING;
  8871.   --| Purpose
  8872.   --| Return the name of the next file.
  8873.   --|
  8874.   --| Exceptions
  8875.   --|   END_OF_FILE_LIST
  8876.   --|
  8877.   --| Notes (none)
  8878.  
  8879.   -- ..............................................
  8880.   -- .                                            .
  8881.   -- . CLP.OUTPUT_FILE_NAME                       . SPEC
  8882.   -- .                                            .
  8883.   -- ..............................................
  8884.   function Output_File_Name return STRING;
  8885.   --| Purpose
  8886.   --| Return the name of the output file.
  8887.   --|
  8888.   --| Exceptions (none)
  8889.   --| Notes (none)
  8890.  
  8891.   -- ..............................................
  8892.   -- .                                            .
  8893.   -- . CLP.FILE_NAME_COUNT                        . SPEC
  8894.   -- .                                            .
  8895.   -- ..............................................
  8896.   function File_Name_Count return NATURAL;
  8897.   --| Purpose
  8898.   --| Number of file names in command line.
  8899.  
  8900.   ALLOCATION_PROBLEM : exception;
  8901.   END_OF_FILE_LIST   : exception;
  8902.   INIT_ERROR         : exception;
  8903.   UNEXPECTED_ERROR   : exception;  -- raised anytime
  8904.  
  8905. end Command_Line_Processor;
  8906. --::::::::::
  8907. --lbintree.spc
  8908. --::::::::::
  8909. -- ********************************************************
  8910. -- *                                                      *
  8911. -- *  LABELED_BINARY_TREES_PKG                            *  SPEC
  8912. -- *                                                      *
  8913. -- ********************************************************
  8914. with Binary_Trees_Pkg;
  8915. generic
  8916.     type LABEL_TYPE is private; -- Type for labels stored in the tree.
  8917.     type VALUE_TYPE is private; -- Type for values stored in the tree.
  8918.     with function Difference (P, Q: LABEL_TYPE) return INTEGER is <>;
  8919.       -- Must return a value > 0 if P > Q, 0 if P = Q, and less than
  8920.       -- zero otherwise, where P and Q are labels.
  8921. package Labeled_Binary_Trees_Pkg is
  8922. --| Purpose
  8923. --| This package provides labeled binary trees, which are the same as
  8924. --| unlabeled binary trees except that when searching for or inserting
  8925. --| a value into the tree, only the label field is compared.
  8926. --| 
  8927. --| Initialization Exceptions (none)
  8928. --|
  8929. --| Notes
  8930. --| USAGE: (See Overview of Binary_Trees_Package)
  8931. --| 
  8932. --| PERFORMANCE: (See Overview of Binary_Trees_Package)
  8933. --|
  8934. --| Modifications
  8935. --| Author: Bill Toscano and Michael Gordon, Intermetrics, Inc.
  8936.  
  8937. -- This should be private (but cannot be)
  8938.  
  8939.   type LABEL_VALUE_PAIR is 
  8940.     record
  8941.       Label : LABEL_TYPE;
  8942.       Value : VALUE_TYPE;
  8943.     end record;
  8944.  
  8945.   function LV_Differ (P, Q: LABEL_VALUE_PAIR) return INTEGER;
  8946.   package LVT is new Binary_Trees_Pkg (LABEL_VALUE_PAIR, LV_Differ);
  8947.  
  8948. -- Exceptions --
  8949.  
  8950.   Duplicate_Value: exception renames LVT.Duplicate_Value;
  8951.   -- Raised on attempt to insert a duplicate label into a tree.
  8952.  
  8953.   Not_Found: exception renames LVT.Not_Found;
  8954.   -- Raised on attempt to find a label that is not in a tree.
  8955.  
  8956.   No_More: exception renames LVT.No_More;
  8957.   -- Raised on attempt to bump an iterator that has already scanned the
  8958.   -- entire tree.
  8959.  
  8960.   Out_Of_Order: exception renames LVT.Out_Of_Order;
  8961.   -- Raised if a problem in the ordering of a tree is detected.
  8962.  
  8963.   Invalid_Tree: exception renames LVT.Invalid_Tree;
  8964.   -- Value is not a tree or was not properly initialized.
  8965.  
  8966. -- Types --
  8967.  
  8968.   subtype SCAN_KIND is LVT.SCAN_KIND;
  8969.  
  8970.   --? function InOrder return LVT.Scan_Kind renames LVT.InOrder;
  8971.  
  8972.   InOrder   : constant SCAN_KIND := LVT.InOrder;
  8973.   PreOrder  : constant SCAN_KIND := LVT.PreOrder;
  8974.   PostOrder : constant SCAN_KIND := LVT.PostOrder;
  8975.  
  8976.   -- is (inorder, preorder, postorder);
  8977.   -- Used to specify the order in which values should be scanned from a tree:
  8978.   --
  8979.   -- inorder: Left, Node, Right (nodes visited in increasing order)
  8980.   -- preorder: Node, Left, Right (top down)
  8981.   -- postorder: Left, Right, Node (bottom up)
  8982.  
  8983.   subtype TREE is LVT.TREE;
  8984.   subtype ITERATOR is LVT.ITERATOR;
  8985.  
  8986. -- Operations --
  8987.  
  8988.   -- ........................................................
  8989.   -- .                                                      .
  8990.   -- .  LABELED_BINARY_TREES_PKG.CREATE                     .  SPEC
  8991.   -- .                                                      .
  8992.   -- ........................................................
  8993.   Function Create return TREE renames LVT.Create;
  8994.   --| Purpose
  8995.   --| Create and return an empty tree.  Note that this allocates
  8996.   --| a small amount of storage which can only be reclaimed through 
  8997.   --| a call to Destroy.
  8998.   --|
  8999.   --| Exceptions (none)
  9000.   --| Notes (none)
  9001.  
  9002.   -- ........................................................
  9003.   -- .                                                      .
  9004.   -- .  LABELED_BINARY_TREES_PKG.INSERT                     .  SPEC
  9005.   -- .                                                      .
  9006.   -- ........................................................
  9007.   Procedure Insert (L: LABEL_TYPE;
  9008.                     V: VALUE_TYPE;
  9009.                     T: TREE);
  9010.   --| Purpose
  9011.   --| Insert (L, V) into T in the proper place.  If a label equal
  9012.   --| to L (according to the Difference function) is already contained
  9013.   --| in the tree, the exception Duplicate_Label is raised.
  9014.   --| Caution: Since this package does not attempt to balance trees as
  9015.   --| values are inserted, it is important to remember that inserting
  9016.   --| labels in sorted order will create a degenerate tree, where search
  9017.   --| and insertion is proportional to the N instead of to Log N.  If
  9018.   --| this pattern is common, use the Balanced_Tree function below.
  9019.   --|
  9020.   --| Exceptions
  9021.   --|   Duplicate_Value
  9022.   --|   Invalid_Tree
  9023.   --|
  9024.   --| Notes (none)
  9025.  
  9026.   -- ........................................................
  9027.   -- .                                                      .
  9028.   -- .  LABELED_BINARY_TREES_PKG.INSERT_IF_NOT_FOUND        .  SPEC
  9029.   -- .                                                      .
  9030.   -- ........................................................
  9031.   procedure Insert_if_not_Found (L         : LABEL_TYPE;
  9032.                                  V         : VALUE_TYPE;
  9033.                                  T         : TREE;
  9034.                                  Found     : out BOOLEAN;
  9035.                                  Duplicate : out VALUE_TYPE);
  9036.   --| Purpose
  9037.   --| Insert V into T in the proper place.  If a value equal
  9038.   --| to V (according to the Difference function) is already contained
  9039.   --| in the tree, Found will be True and Duplicate will be the duplicate
  9040.   --| value.  This might be a sequence of values with the same key, and
  9041.   --| V can then be added to the sequence.
  9042.   --|
  9043.   --| Exceptions
  9044.   --|   Invalid_Tree
  9045.   --|
  9046.   --| Notes (none)
  9047.  
  9048.   -- ........................................................
  9049.   -- .                                                      .
  9050.   -- .  LABELED_BINARY_TREES_PKG.REPLACE_IF_FOUND           .  SPEC
  9051.   -- .                                                      .
  9052.   -- ........................................................
  9053.   procedure Replace_if_Found (L         : LABEL_TYPE;
  9054.                               V         : VALUE_TYPE;
  9055.                               T         : TREE;
  9056.                               Found     : out BOOLEAN;
  9057.                               Old_Value : out VALUE_TYPE);
  9058.   --| Purpose
  9059.   --| Search for L in T.  If found, replace the old value with V,
  9060.   --| and return Found => True, Old_Value => the old value.  Otherwise,
  9061.   --| simply insert the L, V pair into T and return Found => False.
  9062.   --|
  9063.   --| Exceptions
  9064.   --|   Invalid_Tree
  9065.   --|
  9066.   --| Notes (none)
  9067.  
  9068.   -- ........................................................
  9069.   -- .                                                      .
  9070.   -- .  LABELED_BINARY_TREES_PKG.DESTROY                    .  SPEC
  9071.   -- .                                                      .
  9072.   -- ........................................................
  9073.   procedure Destroy (T: in out TREE) renames LVT.Destroy;
  9074.   --| Purpose
  9075.   --| The space allocated to T is reclaimed.  The space occupied by
  9076.   --| the values stored in T is not however, recovered.
  9077.   --|
  9078.   --| Exceptions (none)
  9079.   --| Notes (none)
  9080.  
  9081.   -- ........................................................
  9082.   -- .                                                      .
  9083.   -- .  LABELED_BINARY_TREES_PKG.DESTROY_DEEP               .  SPEC
  9084.   -- .                                                      .
  9085.   -- ........................................................
  9086.   generic
  9087.     with procedure Free_Value (V: in out VALUE_TYPE) is <>;
  9088.     with procedure Free_Label (L: in out LABEL_TYPE) is <>;
  9089.   procedure Destroy_Deep (T: in out TREE);
  9090.   --| Purpose
  9091.   --| The space allocated to T is reclaimed.  The values and
  9092.   --| labels stored it T are reclaimed using Free_Label and
  9093.   --| Free_Value, and the tree nodes themselves
  9094.   --| are then reclaimed (in a single walk of the tree).
  9095.   --|
  9096.   --| Exceptions (none)
  9097.   --| Notes (none)
  9098.  
  9099.   -- ........................................................
  9100.   -- .                                                      .
  9101.   -- .  LABELED_BINARY_TREES_PKG.BALANCED_TREE              .  SPEC
  9102.   -- .                                                      .
  9103.   -- ........................................................
  9104.   generic
  9105.     with procedure Next_Pair (L: in out LABEL_TYPE; V: in out VALUE_TYPE)
  9106.         is <>;
  9107.     -- Each call to this procedure should return the next (Label, Value)
  9108.     -- pair to be
  9109.     -- inserted into the balanced tree being created.  If necessary,
  9110.     -- this function should check that each value is greater than the
  9111.     -- previous one, and raise Out_of_Order if necessary.  If values
  9112.     -- are not returned in strictly increasing order, the results are
  9113.     -- unpredictable.
  9114.   function Balanced_Tree (Count: NATURAL) return TREE;
  9115.   --| Purpose
  9116.   --| Create a balanced tree by calling next_Pair Count times.
  9117.   --| Each time Next_Pair is called, it must return a label that compares
  9118.   --| greater than the preceeding label.  This function is useful for balancing
  9119.   --| an existing tree (next_Pair iterates over the unbalanced tree) or
  9120.   --| for creating a balanced tree when reading data from a file which is
  9121.   --| already sorted.
  9122.   --|
  9123.   --| Exceptions (none)
  9124.   --| Notes (none)
  9125.  
  9126.   -- ........................................................
  9127.   -- .                                                      .
  9128.   -- .  LABELED_BINARY_TREES_PKG.COPY_TREE                  .  SPEC
  9129.   -- .                                                      .
  9130.   -- ........................................................
  9131.   generic
  9132.     with function Copy_Label (L: LABEL_TYPE) return LABEL_TYPE is <>;
  9133.     with function Copy_Value (V: VALUE_TYPE) return VALUE_TYPE is <>;
  9134.     -- This function is called to copy a value from the old tree to the
  9135.     -- new tree.
  9136.   Function Copy_Tree (T: TREE) return TREE;
  9137.   --| Purpose
  9138.   --| Create a balanced tree that is a copy of the tree T.
  9139.   --| The exception Invalid_Tree is raised if T is not a valid tree.
  9140.   --|
  9141.   --| Exceptions
  9142.   --|   Invalid_Tree
  9143.   --|
  9144.   --| Notes (none)
  9145.  
  9146.   -- ........................................................
  9147.   -- .                                                      .
  9148.   -- .  LABELED_BINARY_TREES_PKG.IS_EMPTY                   .  SPEC
  9149.   -- .                                                      .
  9150.   -- ........................................................
  9151.   function Is_Empty (T: TREE) return BOOLEAN renames LVT.Is_Empty;
  9152.   --| Purpose
  9153.   --| Return TRUE iff T is an empty tree or if T was not initialized.
  9154.   --|
  9155.   --| Exceptions (none)
  9156.   --| Notes (none)
  9157.  
  9158.   -- ........................................................
  9159.   -- .                                                      .
  9160.   -- .  LABELED_BINARY_TREES_PKG.FIND                       .  SPEC
  9161.   -- .                                                      .
  9162.   -- ........................................................
  9163.   Function Find (L: LABEL_TYPE;
  9164.                  T: TREE) return VALUE_TYPE;
  9165.   --| Purpose
  9166.   --| Search T for a label that matches L.  The corresponding value
  9167.   --| is returned.  If no matching label is found, the exception Not_Found
  9168.   --| is raised.
  9169.   --|
  9170.   --| Exceptions
  9171.   --|   Not_Found
  9172.   --|   Invalid_Tree
  9173.   --|
  9174.   --| Notes (none)
  9175.  
  9176.   -- ........................................................
  9177.   -- .                                                      .
  9178.   -- .  LABELED_BINARY_TREES_PKG.FIND                       .  SPEC
  9179.   -- .                                                      .
  9180.   -- ........................................................
  9181.   Procedure Find (L     : LABEL_TYPE;
  9182.                   T     : TREE;
  9183.                   Found : out BOOLEAN;
  9184.                   Match : out VALUE_TYPE);
  9185.   --| Purpose
  9186.   --| Search T for a label that matches L.  On return, if Found is
  9187.   --| TRUE then the corresponding value is returned in Match.  Otherwise,
  9188.   --| Found is FALSE and Match is undefined.
  9189.   --|
  9190.   --| Exceptions
  9191.   --|   Invalid_Tree
  9192.   --|
  9193.   --| Notes (none)
  9194.  
  9195.   -- ........................................................
  9196.   -- .                                                      .
  9197.   -- .  LABELED_BINARY_TREES_PKG.IS_FOUND                   .  SPEC
  9198.   -- .                                                      .
  9199.   -- ........................................................
  9200.   function Is_Found (L: LABEL_TYPE;
  9201.                      T: TREE) return BOOLEAN;
  9202.   --| Purpose
  9203.   --| Return TRUE iff L is found in T.
  9204.   --|
  9205.   --| Exceptions
  9206.   --|   Invalid_Tree
  9207.   --|
  9208.   --| Notes (none)
  9209.  
  9210.   -- ........................................................
  9211.   -- .                                                      .
  9212.   -- .  LABELED_BINARY_TREES_PKG.SIZE                       .  SPEC
  9213.   -- .                                                      .
  9214.   -- ........................................................
  9215.   function Size (T: TREE) return NATURAL renames LVT.Size; 
  9216.   --| Purpose
  9217.   --| Return the number of values stored in T.
  9218.   --|
  9219.   --| Exceptions (none)
  9220.   --| Notes (none)
  9221.  
  9222.   -- ........................................................
  9223.   -- .                                                      .
  9224.   -- .  LABELED_BINARY_TREES_PKG.VISIT                      .  SPEC
  9225.   -- .                                                      .
  9226.   -- ........................................................
  9227.   generic
  9228.     with procedure Process(L: LABEL_TYPE; V: VALUE_TYPE) is <>;
  9229.   procedure Visit (T     : TREE;
  9230.                    Order : SCAN_KIND);
  9231.   --| Purpose
  9232.   --| Invoke Process(V) for each value V in T.  The nodes are visited
  9233.   --| in the order specified by Order.  Although more limited than using
  9234.   --| an iterator, this function is also much faster.
  9235.   --|
  9236.   --| Exceptions
  9237.   --|   Invalid_Tree
  9238.   --|
  9239.   --| Notes (none)
  9240.  
  9241.   -- ........................................................
  9242.   -- .                                                      .
  9243.   -- .  LABELED_BINARY_TREES_PKG.MAKE_ITER                  .  SPEC
  9244.   -- .                                                      .
  9245.   -- ........................................................
  9246.   function Make_Iter (T: TREE) return ITERATOR renames LVT.Make_Iter;
  9247.   --| Purpose
  9248.   --| Create an iterator over a tree.
  9249.   --|
  9250.   --| Exceptions
  9251.   --|   Invalid_Tree
  9252.   --|
  9253.   --| Notes (none)
  9254.  
  9255.   -- ........................................................
  9256.   -- .                                                      .
  9257.   -- .  LABELED_BINARY_TREES_PKG.MORE                       .  SPEC
  9258.   -- .                                                      .
  9259.   -- ........................................................
  9260.   function More (I: ITERATOR) return BOOLEAN renames LVT.More;
  9261.   --| Purpose
  9262.   --| Return TRUE iff unscanned nodes remain in the tree being
  9263.   --| scanned by I.
  9264.   --|
  9265.   --| Exceptions (none)
  9266.   --| Notes (none)
  9267.  
  9268.   -- ........................................................
  9269.   -- .                                                      .
  9270.   -- .  LABELED_BINARY_TREES_PKG.NEXT                       .  SPEC
  9271.   -- .                                                      .
  9272.   -- ........................................................
  9273.   procedure Next (I: in out ITERATOR;
  9274.                   L: out LABEL_TYPE;
  9275.                   V: out VALUE_TYPE);
  9276.   --| Purpose
  9277.   --| Return the next value in the tree being scanned by I.
  9278.   --| The exception No_More is raised if there are no more values to scan.
  9279.   --|
  9280.   --| Exceptions
  9281.   --|   No_More
  9282.   --|
  9283.   --| Notes (none)
  9284.  
  9285. end Labeled_Binary_Trees_Pkg;
  9286. --::::::::::
  9287. --ordset.spc
  9288. --::::::::::
  9289. -- ****************************************************
  9290. -- *                                                  *
  9291. -- *  ORDEREDSETS                                     *  SPEC
  9292. -- *                                                  *
  9293. -- ****************************************************
  9294. with BinaryTrees;
  9295. generic
  9296.       type ITEMTYPE is private;
  9297.       with function "<" (X, Y : in ITEMTYPE) return BOOLEAN;
  9298. package OrderedSets is
  9299. --| Purpose
  9300. --| This abstractions is a counted ordered set.  This means that 
  9301. --| associated with each member of the set is a count of the number of
  9302. --| times it appears in the set.  The order part means that there is
  9303. --| an ordering associated with the members.  This allows fast insertion.
  9304. --| It also makes it easy to iterate over the set in order.
  9305. --|
  9306. --| Initialization Exceptions (none)
  9307. --| Notes (none)
  9308. --|
  9309. --| Modifications
  9310. --| Author: Bill Toscano and Michael Gordon, Intermetrics
  9311.  
  9312.       type SET is private;
  9313.       type SETITER is private;
  9314.  
  9315.   -- .....................................................
  9316.   -- .                                                   .
  9317.   -- .  ORDEREDSETS.CARDINALITY                          .  SPEC
  9318.   -- .                                                   .
  9319.   -- .....................................................
  9320.   function Cardinality (S : in SET) return NATURAL;
  9321.   --| Purpose
  9322.   --| Return the number of members in the set.
  9323.   --|
  9324.   --| Exceptions (none)
  9325.   --| Notes (none)
  9326.  
  9327.   -- .....................................................
  9328.   -- .                                                   .
  9329.   -- .  ORDEREDSETS.CREATE                               .  SPEC
  9330.   -- .                                                   .
  9331.   -- .....................................................
  9332.   function Create return SET;
  9333.   --| Purpose
  9334.   --| Return the empty set.
  9335.   --|
  9336.   --| Exceptions (none)
  9337.   --| Notes (none)
  9338.  
  9339.   -- .....................................................
  9340.   -- .                                                   .
  9341.   -- .  ORDEREDSETS.DESTROY                              .  SPEC
  9342.   -- .                                                   .
  9343.   -- .....................................................
  9344.   procedure Destroy (S : in out SET);
  9345.   --| Purpose
  9346.   --| Destroy a set and return its space.
  9347.   --|
  9348.   --| Exceptions (none)
  9349.   --| Notes (none)
  9350.  
  9351.   -- .....................................................
  9352.   -- .                                                   .
  9353.   -- .  ORDEREDSETS.GETCOUNT                             .  SPEC
  9354.   -- .                                                   .
  9355.   -- .....................................................
  9356.   function GetCount (I : in SETITER) return NATURAL;
  9357.   --| Purpose
  9358.   --| Returns the count associated with the member corresponding to the
  9359.   --| current interator I.
  9360.   --|
  9361.   --| Exceptions (none)
  9362.   --| Notes (none)
  9363.  
  9364.   -- .....................................................
  9365.   -- .                                                   .
  9366.   -- .  ORDEREDSETS.INSERT                               .  SPEC
  9367.   -- .                                                   .
  9368.   -- .....................................................
  9369.   procedure Insert (M : in ITEMTYPE;
  9370.                     S : in out SET);
  9371.   --| Purpose
  9372.   --| Insert a member M into set S.
  9373.   --|
  9374.   --| Exceptions (none)
  9375.   --| Notes (none)
  9376.  
  9377.   -- .....................................................
  9378.   -- .                                                   .
  9379.   -- .  ORDEREDSETS.MAKESETITER                          .  SPEC
  9380.   -- .                                                   .
  9381.   -- .....................................................
  9382.   function MakeSetIter (S : in SET) return SETITER;
  9383.   --| Purpose
  9384.   --| Prepares a user for an iteration operation by returning
  9385.   --| a SetIter.
  9386.   --|
  9387.   --| Exceptions (none)
  9388.   --| Notes (none)
  9389.  
  9390.   -- .....................................................
  9391.   -- .                                                   .
  9392.   -- .  ORDEREDSETS.MORE                                 .  SPEC
  9393.   -- .                                                   .
  9394.   -- .....................................................
  9395.   function More (I : in SETITER) return BOOLEAN;
  9396.   --| Purpose
  9397.   --| Returns TRUE if there are more elements in the set
  9398.   --| to iterate over.
  9399.   --|
  9400.   --| Exceptions (none)
  9401.   --| Notes (none)
  9402.  
  9403.   -- .....................................................
  9404.   -- .                                                   .
  9405.   -- .  ORDEREDSETS.NEXT                                 .  SPEC
  9406.   -- .                                                   .
  9407.   -- .....................................................
  9408.   procedure Next (I : in out SETITER;
  9409.                   M : out ITEMTYPE);
  9410.   --| Purpose
  9411.   --| Returns the current member in the iteration and increments
  9412.   --| the iterator.
  9413.   --|
  9414.   --| Exceptions (none)
  9415.   --| Notes (none)
  9416.  
  9417. private 
  9418.    type MEMBER is 
  9419.        record 
  9420.          Info  : ITEMTYPE;
  9421.          Count : NATURAL;
  9422.        end record;
  9423.  
  9424.    function "<" (X: in MEMBER; Y: in MEMBER) return BOOLEAN;
  9425.  
  9426.    package TreePkg is new BinaryTrees (ITEMTYPE => MEMBER, "<" => "<");
  9427.  
  9428.    type SET is
  9429.        record 
  9430.          SetRep :TreePkg.TREE;
  9431.        end record;
  9432.  
  9433.    type SETITER is
  9434.        record
  9435.          Place : TreePkg.TREEITER;
  9436.          Count : NATURAL;
  9437.        end record;
  9438.  
  9439. end OrderedSets;
  9440. --::::::::::
  9441. --string.spc
  9442. --::::::::::
  9443. -- **********************************************
  9444. -- *                                            *
  9445. -- *  STRING_PKG                                *  SPEC
  9446. -- *                                            *
  9447. -- **********************************************
  9448. package String_Pkg is
  9449. --| Purpose
  9450. --| Package string_pkg exports an abstract data type, string_type.  A
  9451. --| string_type value is a sequence of characters.  The values have arbitrary
  9452. --| length.  For a value, s, with length, l, the individual characters are
  9453. --| numbered from 1 to l.  These values are immutable; characters cannot be
  9454. --| replaced or appended in a destructive fashion.  
  9455. --|
  9456. --| In the documentation for this package, we are careful to distinguish 
  9457. --| between string_type objects, which are Ada objects in the usual sense, 
  9458. --| and string_type values, the members of this data abstraction as described
  9459. --| above.  A string_type value is said to be associated with, or bound to,
  9460. --| a string_type object after an assignment (:=) operation.  
  9461. --| 
  9462. --| The operations provided in this package fall into three categories: 
  9463. --|
  9464. --| 1. Constructors:  These functions typically take one or more string_type
  9465. --|      objects as arguments.  They work with the values associated with 
  9466. --|      these objects, and return new string_type values according to 
  9467. --|      specification.  By a slight abuse of language, we will sometimes 
  9468. --|      coerce from string_type objects to values for ease in description.
  9469. --|
  9470. --| 2. Heap Management:   
  9471. --|      These operations (make_persistent, flush, mark, release) control the
  9472. --|      management of heap space.  Because string_type values are
  9473. --|      allocated on the heap, and the type is not limited, it is necessary
  9474. --|      for a user to assume some responsibility for garbage collection.  
  9475. --|      String_type is not limited because of the convenience of
  9476. --|      the assignment operation, and the usefulness of being able to 
  9477. --|      instantiate generic units that contain private type formals.  
  9478. --|      ** Important: To use this package properly, it is necessary to read
  9479. --|      the descriptions of the operations in this section.
  9480. --|
  9481. --| 3. Queries:  These functions return information about the values 
  9482. --|      that are associated with the argument objects.  The same conventions 
  9483. --|      for description of operations used in (1) is adopted.
  9484. --| 
  9485. --| A note about design decisions...  The decision to not make the type 
  9486. --| limited causes two operations to be carried over from the representation.
  9487. --| These are the assignment operation, :=, and the "equality" operator, "=".
  9488. --| See the discussion at the beginning of the Heap Management section for a 
  9489. --| discussion of :=.
  9490. --| See the spec for the first of the equal functions for a discussion of "=".
  9491. --| 
  9492. --| Initialization Exceptions (none)
  9493. --| Notes (none)
  9494. --|
  9495. --| Modifications
  9496. --| Programmer: Ron Kownacki, Intermetrics
  9497.  
  9498.     type STRING_TYPE is private;
  9499.     type COMPARISON_OPTION is (CASE_SENSITIVE, CASE_INSENSITIVE);
  9500.     -- Used for equal, "<" and "<=" functions.  If the comparison_option
  9501.     -- is case_sensitive, then a straightforward comparison of values
  9502.     -- is performed.  If the option is case_insensitive, then comparison
  9503.     -- between the arguments is performed after first normalizing them to
  9504.     -- lower case.
  9505.  
  9506.     Bounds:          exception;  -- Raised on index out of bounds.
  9507.     Any_Empty:       exception;  -- Raised on incorrect use of match_any.
  9508.     Illegal_Alloc:   exception;  -- Raised by value creating operations.
  9509.     Illegal_Dealloc: exception;  -- Raised by release.
  9510.     
  9511. -- Constructors:
  9512.  
  9513.   -- ...............................................
  9514.   -- .                                             .
  9515.   -- .  STRING_PKG.CREATE                          .  SPEC
  9516.   -- .                                             .
  9517.   -- ...............................................
  9518.   function Create (S: in STRING) return STRING_TYPE;
  9519.   --| Purpose
  9520.   --| Return a value consisting of the sequence of characters in s.
  9521.   --| Sometimes useful for array or record aggregates.
  9522.   --| Raises illegal_alloc if string space has been improperly
  9523.   --| released.  (See procedures mark/release.)
  9524.   --|
  9525.   --| Exceptions
  9526.   --|   illegal_alloc
  9527.   --|
  9528.   --| Notes (none)
  9529.  
  9530.   -- ...............................................
  9531.   -- .                                             .
  9532.   -- .  STRING_PKG.&                               .  SPEC
  9533.   -- .                                             .
  9534.   -- ...............................................
  9535.   function "&" (S1, S2: in STRING_TYPE) return STRING_TYPE;
  9536.   --| Purpose
  9537.   --| Return the concatenation of s1 and s2.
  9538.   --| Raises illegal_alloc if string space has been improperly
  9539.   --| released.  (See procedures mark/release.)
  9540.   --|
  9541.   --| Exceptions
  9542.   --|   illegal_alloc
  9543.   --|
  9544.   --| Notes (none)
  9545.  
  9546.   -- ...............................................
  9547.   -- .                                             .
  9548.   -- .  STRING_PKG.&                               .  SPEC
  9549.   -- .                                             .
  9550.   -- ...............................................
  9551.   function "&" (S1: in STRING_TYPE; S2: in STRING) return STRING_TYPE;
  9552.   --| Purpose
  9553.   --| Return the concatenation of s1 and create(s2).
  9554.   --| Raises illegal_alloc if string space has been improperly
  9555.   --| released.  (See procedures mark/release.)
  9556.   --|
  9557.   --| Exceptions
  9558.   --|   illegal_alloc
  9559.   --|
  9560.   --| Notes (none)
  9561.  
  9562.   -- ...............................................
  9563.   -- .                                             .
  9564.   -- .  STRING_PKG.&                               .  SPEC
  9565.   -- .                                             .
  9566.   -- ...............................................
  9567.   function "&" (S1: in STRING; S2: in STRING_TYPE) return STRING_TYPE;
  9568.   --| Purpose
  9569.   --| Return the concatenation of create(s1) and s2.
  9570.   --| Raises illegal_alloc if string space has been improperly
  9571.   --| released.  (See procedures mark/release.)
  9572.   --|
  9573.   --| Exceptions
  9574.   --|   illegal_alloc
  9575.   --|
  9576.   --| Notes (none)
  9577.  
  9578.   -- ...............................................
  9579.   -- .                                             .
  9580.   -- .  STRING_PKG.SUBSTR                          .  SPEC
  9581.   -- .                                             .
  9582.   -- ...............................................
  9583.   function Substr (S   : in STRING_TYPE;
  9584.                    I   : in POSITIVE;
  9585.                    Len : in NATURAL)
  9586.       return STRING_TYPE;
  9587.   --| Purpose
  9588.   --| Return the substring, of specified length, that occurs in s at
  9589.   --| position i.  If len = 0, then returns the empty value.  
  9590.   --| Otherwise, raises bounds if either i or (i + len - 1)
  9591.   --| is not in 1..length(s).
  9592.   --| Raises illegal_alloc if string space has been improperly
  9593.   --| released.  (See procedures mark/release.)
  9594.   --|
  9595.   --| Exceptions
  9596.   --|   illegal_alloc
  9597.   --|
  9598.   --| Notes (none)
  9599.   
  9600.   -- ...............................................
  9601.   -- .                                             .
  9602.   -- .  STRING_PKG.SPLICE                          .  SPEC
  9603.   -- .                                             .
  9604.   -- ...............................................
  9605.   function Splice (S   : in STRING_TYPE;
  9606.                    I   : in POSITIVE;
  9607.                    Len : in NATURAL)
  9608.       return STRING_TYPE;
  9609.   --| Purpose
  9610.   --| Let s be the string, abc, where a, b and c are substrings.  If
  9611.   --| substr(s, i, length(b)) = b, for some i in 1..length(s), then
  9612.   --| splice(s, i, length(b)) = ac.  
  9613.   --| Returns a value equal to s if len = 0.  Otherwise, raises bounds if
  9614.   --| either i or (i + len - 1) is not in 1..length(s).
  9615.   --| Raises illegal_alloc if string space has been improperly
  9616.   --| released.  (See procedures mark/release.)
  9617.   --|
  9618.   --| Exceptions
  9619.   --|   illegal_alloc
  9620.   --|
  9621.   --| Notes (none)
  9622.   
  9623.   -- ...............................................
  9624.   -- .                                             .
  9625.   -- .  STRING_PKG.INSERT                          .  SPEC
  9626.   -- .                                             .
  9627.   -- ...............................................
  9628.   function Insert (S1, S2: in STRING_TYPE; I: in POSITIVE)
  9629.       return STRING_TYPE;
  9630.   --| Purpose
  9631.   --| Return substr(s1, 1, i - 1) & s2 & substr(s1, i, length(s1)).
  9632.   --| equal(splice(insert(s1, s2, i), i, length(s2)), s1) holds if no
  9633.   --| exception is raised by insert.
  9634.   --| Raises bounds if i is not in 1..length(s1) + 1.
  9635.   --| Raises illegal_alloc if string space has been improperly
  9636.   --| released.  (See procedures mark/release.)
  9637.   --|
  9638.   --| Exceptions
  9639.   --|   bounds
  9640.   --|   illegal_alloc
  9641.   --|
  9642.   --| Notes (none)
  9643.  
  9644.   -- ...............................................
  9645.   -- .                                             .
  9646.   -- .  STRING_PKG.INSERT                          .  SPEC
  9647.   -- .                                             .
  9648.   -- ...............................................
  9649.   function Insert (S1 : in STRING_TYPE;
  9650.                    S2 : in STRING;
  9651.                    I  : in POSITIVE)
  9652.       return STRING_TYPE;
  9653.   --| Purpose
  9654.   --| Return substr(s1, 1, i - 1) & s2 & substr(s1, i, length(s1)).
  9655.   --| equal(splice(insert(s1, s2, i), i, length(s2)), s1) holds if no
  9656.   --| exception is raised by insert.
  9657.   --| Raises bounds if i is not in 1..length(s1) + 1.
  9658.   --| Raises illegal_alloc if string space has been improperly
  9659.   --| released.  (See procedures mark/release.)
  9660.   --|
  9661.   --| Exceptions
  9662.   --|   bounds
  9663.   --|   illegal_alloc
  9664.   --|
  9665.   --| Notes (none)
  9666.       
  9667.   -- ...............................................
  9668.   -- .                                             .
  9669.   -- .  STRING_PKG.INSERT                          .  SPEC
  9670.   -- .                                             .
  9671.   -- ...............................................
  9672.   function Insert (S1 : in STRING;
  9673.                    S2 : in STRING_TYPE;
  9674.                    I  : in POSITIVE)
  9675.       return STRING_TYPE;
  9676.   --| Purpose
  9677.   --| Return s1(s1'first..i - 1) & s2 & s1(i..s1'last).
  9678.   --| equal(splice(insert(s1, s2, i), i, length(s2)), s1) holds if no
  9679.   --| exception is raised by insert.
  9680.   --| Raises bounds if i is not in s'first..s'last + 1.
  9681.   --| Raises illegal_alloc if string space has been improperly
  9682.   --| released.  (See procedures mark/release.)
  9683.   --|
  9684.   --| Exceptions
  9685.   --|   bounds
  9686.   --|   illegal_alloc
  9687.   --|
  9688.   --| Notes (none)
  9689.       
  9690.   -- ...............................................
  9691.   -- .                                             .
  9692.   -- .  STRING_PKG.LOWER                           .  SPEC
  9693.   -- .                                             .
  9694.   -- ...............................................
  9695.   function Lower (S: in STRING) return STRING_TYPE;
  9696.   --| Purpose
  9697.   --| Return a value that contains exactly those characters in s with
  9698.   --| the exception that all upper case characters are replaced by their 
  9699.   --| lower case counterparts.
  9700.   --| Raises illegal_alloc if string space has been improperly
  9701.   --| released.  (See procedures mark/release.)
  9702.   --|
  9703.   --| Exceptions
  9704.   --|   illegal_alloc
  9705.   --|
  9706.   --| Notes (none)
  9707.  
  9708.   -- ...............................................
  9709.   -- .                                             .
  9710.   -- .  STRING_PKG.LOWER                           .  SPEC
  9711.   -- .                                             .
  9712.   -- ...............................................
  9713.   function Lower (S: in STRING_TYPE) return STRING_TYPE;
  9714.   --| Purpose
  9715.   --| Return a value that is a copy of s with the exception that all
  9716.   --| upper case characters are replaced by their lower case counterparts.
  9717.   --| Raises illegal_alloc if string space has been improperly
  9718.   --| released.  (See procedures mark/release.)
  9719.   --|
  9720.   --| Exceptions
  9721.   --|   illegal_alloc
  9722.   --|
  9723.   --| Notes (none)
  9724.  
  9725.   -- ...............................................
  9726.   -- .                                             .
  9727.   -- .  STRING_PKG.UPPER                           .  SPEC
  9728.   -- .                                             .
  9729.   -- ...............................................
  9730.   function Upper (S: in STRING) return STRING_TYPE;
  9731.   --| Purpose
  9732.   --| Return a value that contains exactly those characters in s with
  9733.   --| the exception that all lower case characters are replaced by their 
  9734.   --| upper case counterparts.
  9735.   --| Raises illegal_alloc if string space has been improperly
  9736.   --| released.  (See procedures mark/release.)
  9737.   --|
  9738.   --| Exceptions
  9739.   --|   illegal_alloc
  9740.   --|
  9741.   --| Notes (none)
  9742.  
  9743.   -- ...............................................
  9744.   -- .                                             .
  9745.   -- .  STRING_PKG.UPPER                           .  SPEC
  9746.   -- .                                             .
  9747.   -- ...............................................
  9748.   function Upper (S: in STRING_TYPE) return STRING_TYPE;
  9749.   --| Purpose
  9750.   --| Return a value that is a copy of s with the exception that all
  9751.   --| lower case characters are replaced by their upper case counterparts.
  9752.   --| Raises illegal_alloc if string space has been improperly
  9753.   --| released.  (See procedures mark/release.)
  9754.   --|
  9755.   --| Exceptions
  9756.   --|   illegal_alloc
  9757.   --|
  9758.   --| Notes (none)
  9759.       
  9760.  
  9761. -- Heap Management (including object/value binding):
  9762. --
  9763. -- Two forms of heap management are provided.  The general scheme is to "mark"
  9764. -- the current state of heap usage, and to "release" in order to reclaim all
  9765. -- space that has been used since the last mark.  However, this alone is 
  9766. -- insufficient because it is frequently desirable for objects to remain 
  9767. -- associated with values for longer periods of time, and this may come into 
  9768. -- conflict with the need to clean up after a period of "string hacking."
  9769. -- To deal with this problem, we introduce the notions of "persistent" and
  9770. -- "nonpersistent" values.
  9771. --
  9772. -- The nonpersistent values are those that are generated by the constructors 
  9773. -- in the previous section.  These are claimed by the release procedure.
  9774. -- Persistent values are generated by the two make_persistent functions
  9775. -- described below.  These values must be disposed of individually by means of
  9776. -- the flush procedure.  
  9777. --
  9778. -- This allows a description of the meaning of the ":=" operation.  For a 
  9779. -- statement of the form, s := expr, where expr is a STRING_TYPE expression, 
  9780. -- the result is that the value denoted/created by expr becomes bound to the
  9781. -- the object, s.  Assignment in no way affects the persistence of the value.
  9782. -- If expr happens to be an object, then the value associated  with it will be
  9783. -- shared.  Ideally, this sharing would not be visible, since values are
  9784. -- immutable.  However, the sharing may be visible because of the memory
  9785. -- management, as described below.  Programs which depend on such sharing are 
  9786. -- erroneous.
  9787.    
  9788.   -- ...............................................
  9789.   -- .                                             .
  9790.   -- .  STRING_PKG.MAKE_PERSISTENT                 .  SPEC
  9791.   -- .                                             .
  9792.   -- ...............................................
  9793.   function Make_Persistent (S: in STRING_TYPE) return STRING_TYPE; 
  9794.   --| Purpose 
  9795.   --| Returns a persistent value, v, containing exactly those characters in
  9796.   --| value(s).  The value v will not be claimed by any subsequent release.
  9797.   --| Only an invocation of flush will claim v.  After such a claiming
  9798.   --| invocation of flush, the use (other than :=) of any other object to 
  9799.   --| which v was bound is erroneous, and program_error may be raised for
  9800.   --| such a use.
  9801.   --|
  9802.   --| Exceptions (none)
  9803.   --| Notes (none)
  9804.  
  9805.   -- ...............................................
  9806.   -- .                                             .
  9807.   -- .  STRING_PKG.MAKE_PERSISTENT                 .  SPEC
  9808.   -- .                                             .
  9809.   -- ...............................................
  9810.   function Make_Persistent (S: in STRING) return STRING_TYPE; 
  9811.   --| Purpose 
  9812.   --| Returns a persistent value, v, containing exactly those chars in s.
  9813.   --| The value v will not be claimed by any subsequent release.
  9814.   --| Only an invocation of flush will reclaim v.  After such a claiming
  9815.   --| invocation of flush, the use (other than :=) of any other object to 
  9816.   --| which v was bound is erroneous, and program_error may be raised for
  9817.   --| such a use.
  9818.   --|
  9819.   --| Exceptions (none)
  9820.   --| Notes (none)
  9821.     
  9822.   -- ...............................................
  9823.   -- .                                             .
  9824.   -- .  STRING_PKG.FLUSH                           .  SPEC
  9825.   -- .                                             .
  9826.   -- ...............................................
  9827.   procedure Flush (S: in out STRING_TYPE);
  9828.   --| Purpose
  9829.   --| Return heap space used by the value associated with s, if any, to 
  9830.   --| the heap.  s becomes associated with the empty value.  After an
  9831.   --| invocation of flush claims the value, v, then any use (other than :=)
  9832.   --| of an object to which v was bound is erroneous, and program_error 
  9833.   --| may be raised for such a use.
  9834.   --| 
  9835.   --| This operation should be used only for persistent values.  The mark 
  9836.   --| and release operations are used to deallocate space consumed by other
  9837.   --| values.  For example, flushing a nonpersistent value implies that a
  9838.   --| release that tries to claim this value will be erroneous, and
  9839.   --| program_error may be raised for such a use.
  9840.   --|
  9841.   --| Exceptions (none)
  9842.   --| Notes (none)
  9843.  
  9844.   -- ...............................................
  9845.   -- .                                             .
  9846.   -- .  STRING_PKG.MARK                            .  SPEC
  9847.   -- .                                             .
  9848.   -- ...............................................
  9849.   procedure Mark;
  9850.   --| Purpose
  9851.   --| Marks the current state of heap usage for use by release.  
  9852.   --| An implicit mark is performed at the beginning of program execution.
  9853.   --|
  9854.   --| Exceptions (none)
  9855.   --| Notes (none)
  9856.  
  9857.   -- ...............................................
  9858.   -- .                                             .
  9859.   -- .  STRING_PKG.RELEASE                         .  SPEC
  9860.   -- .                                             .
  9861.   -- ...............................................
  9862.   procedure Release;
  9863.   --| Purpose
  9864.   --| Releases all heap space used by nonpersistent values that have been
  9865.   --| allocated since the last mark.  The values that are claimed include
  9866.   --| those bound to objects as well as those produced and discarded during
  9867.   --| the course of general "string hacking."  If an invocation of release
  9868.   --| claims a value, v, then any subsequent use (other than :=) of any 
  9869.   --| other object to which v is bound is erroneous, and program_error may
  9870.   --| be raised for such a use.
  9871.   --|
  9872.   --| Raises illegal_dealloc if the invocation of release does not balance
  9873.   --| an invocation of mark.  It is permissible to match the implicit
  9874.   --| initial invocation of mark.  However, subsequent invocations of 
  9875.   --| constructors will raise the illegal_alloc exception until an 
  9876.   --| additional mark is performed.  (Anyway, there is no good reason to 
  9877.   --| do this.)  In any case, a number of releases matching the number of
  9878.   --| currently active marks is implicitly performed at the end of program
  9879.   --| execution.
  9880.   --|
  9881.   --| Good citizens generally perform their own marks and releases
  9882.   --| explicitly.  Extensive string hacking without cleaning up will 
  9883.   --| cause your program to run very slowly, since the heap manager will
  9884.   --| be forced to look hard for chunks of space to allocate.
  9885.   --|
  9886.   --| Exceptions
  9887.   --|   illegal_dealloc
  9888.   --|
  9889.   --| Notes (none)
  9890.       
  9891. -- Queries:
  9892.       
  9893.   -- ...............................................
  9894.   -- .                                             .
  9895.   -- .  STRING_PKG.IS_EMPTY                        .  SPEC
  9896.   -- .                                             .
  9897.   -- ...............................................
  9898.   function Is_Empty (S: in STRING_TYPE) return BOOLEAN;
  9899.   --| Purpose
  9900.   --| Return TRUE iff s is the empty sequence of characters.
  9901.   --|
  9902.   --| Exceptions (none)
  9903.   --| Notes (none)
  9904.  
  9905.   -- ...............................................
  9906.   -- .                                             .
  9907.   -- .  STRING_PKG.LENGTH                          .  SPEC
  9908.   -- .                                             .
  9909.   -- ...............................................
  9910.   function Length (S: in STRING_TYPE) return NATURAL;
  9911.   --| Purpose
  9912.   --| Return number of characters in s.
  9913.   --|
  9914.   --| Exceptions (none)
  9915.   --| Notes (none)
  9916.  
  9917.   -- ...............................................
  9918.   -- .                                             .
  9919.   -- .  STRING_PKG.VALUE                           .  SPEC
  9920.   -- .                                             .
  9921.   -- ...............................................
  9922.   function Value (S: in STRING_TYPE) return STRING;
  9923.   --| Purpose
  9924.   --| Return a string, s2, that contains the same characters that s
  9925.   --| contains.  The properties, s2'first = 1 and s2'last = length(s),
  9926.   --| are satisfied.  This implies that, for a given string, s3,
  9927.   --| value(create(s3))'first may not equal s3'first, even though
  9928.   --| value(create(s3)) = s3 holds.  Thus, "content equality" applies
  9929.   --| although the string objects may be distinguished by the use of
  9930.   --| the array attributes.
  9931.   --|
  9932.   --| Exceptions (none)
  9933.   --| Notes (none)
  9934.  
  9935.   -- ...............................................
  9936.   -- .                                             .
  9937.   -- .  STRING_PKG.FETCH                           .  SPEC
  9938.   -- .                                             .
  9939.   -- ...............................................
  9940.   function Fetch (S: in STRING_TYPE;
  9941.                   I: in POSITIVE) return CHARACTER;
  9942.   --| Purpose
  9943.   --| Return the ith character in s.  Characters are numbered from
  9944.   --| 1 to length(s).  Raises bounds if i not in 1..length(s).
  9945.   --|
  9946.   --| Exceptions
  9947.   --|   bounds
  9948.   --|
  9949.   --| Notes (none)
  9950.  
  9951.   -- ...............................................
  9952.   -- .                                             .
  9953.   -- .  STRING_PKG.SET_COMPARISON_OPTION           .  SPEC
  9954.   -- .                                             .
  9955.   -- ...............................................
  9956.   procedure Set_Comparison_Option (Choice: in COMPARISON_OPTION);
  9957.   --| Purpose 
  9958.   --| Set the comparison option for equal, "<" and "<="  (as described
  9959.   --| above) to the given choice.  The initial setting is case_sensitive.
  9960.   --|
  9961.   --| Exceptions (none)
  9962.   --| Notes (none)
  9963.  
  9964.   -- ...............................................
  9965.   -- .                                             .
  9966.   -- .  STRING_PKG.GET_COMPARISON_OPTION           .  SPEC
  9967.   -- .                                             .
  9968.   -- ...............................................
  9969.   function Get_Comparison_Option return COMPARISON_OPTION;
  9970.   --| Purpose 
  9971.   --| Return the current comparison_option setting.
  9972.   --|
  9973.   --| Exceptions (none)
  9974.   --| Notes (none)
  9975.  
  9976.   -- ...............................................
  9977.   -- .                                             .
  9978.   -- .  STRING_PKG.EQUAL                           .  SPEC
  9979.   -- .                                             .
  9980.   -- ...............................................
  9981.   function Equal (S1, S2: in STRING_TYPE) return BOOLEAN;
  9982.   --| Purpose
  9983.   --| Value equality relation; return true iff length(s1) = length(s2)
  9984.   --| and, for all i in 1..length(s1), fetch(s1, i) = fetch(s2, i).
  9985.   --| (If the comparison_option is currently case_insensitive, then 
  9986.   --| lower(s1) and lower(s2) are used instead.)
  9987.   --|
  9988.   --| Exceptions (none)
  9989.   --| 
  9990.   --| Notes
  9991.   --| The "=" operation is carried over from the representation.
  9992.   --| It allows one to distinguish among the heap addresses of
  9993.   --| STRING_TYPE values.  Even "equal" values under case_sensitive 
  9994.   --| comparison may not be "=", although s1 = s2 implies equal(s1, s2).
  9995.   --| There is no reason to use "=".
  9996.  
  9997.   -- ...............................................
  9998.   -- .                                             .
  9999.   -- .  STRING_PKG.EQUAL                           .  SPEC
  10000.   -- .                                             .
  10001.   -- ...............................................
  10002.   function Equal (S1: in STRING_TYPE; S2: in STRING) return BOOLEAN;
  10003.   --| Purpose
  10004.   --| Return equal(s1, create(s2)).
  10005.   --|
  10006.   --| Exceptions (none)
  10007.   --| Notes (none)
  10008.  
  10009.   -- ...............................................
  10010.   -- .                                             .
  10011.   -- .  STRING_PKG.EQUAL                           .  SPEC
  10012.   -- .                                             .
  10013.   -- ...............................................
  10014.   function Equal (S1: in STRING; S2: in STRING_TYPE) return BOOLEAN;
  10015.   --| Purpose
  10016.   --| Return equal(create(s1), s2).
  10017.   --|
  10018.   --| Exceptions (none)
  10019.   --| Notes (none)
  10020.  
  10021.   -- ...............................................
  10022.   -- .                                             .
  10023.   -- .  STRING_PKG."<"                             .  SPEC
  10024.   -- .                                             .
  10025.   -- ...............................................
  10026.   function "<" (S1, S2: in STRING_TYPE) return BOOLEAN;
  10027.   --| Purpose 
  10028.   --| Lexicographic comparison according to the current comparison_option;
  10029.   --| return value(s1) < value(s2).
  10030.   --|
  10031.   --| Exceptions (none)
  10032.   --| Notes (none)
  10033.  
  10034.   -- ...............................................
  10035.   -- .                                             .
  10036.   -- .  STRING_PKG."<"                             .  SPEC
  10037.   -- .                                             .
  10038.   -- ...............................................
  10039.   function "<" (S1: in STRING_TYPE; S2: in STRING) return BOOLEAN;
  10040.   --| Purpose 
  10041.   --| Lexicographic comparison according to the current comparison_option;
  10042.   --| return value(s1) < s2.
  10043.   --|
  10044.   --| Exceptions (none)
  10045.   --| Notes (none)
  10046.  
  10047.   -- ...............................................
  10048.   -- .                                             .
  10049.   -- .  STRING_PKG."<"                             .  SPEC
  10050.   -- .                                             .
  10051.   -- ...............................................
  10052.   function "<" (S1: in STRING; S2: in STRING_TYPE) return BOOLEAN;
  10053.   --| Purpose 
  10054.   --| Lexicographic comparison according to the current comparison_option;
  10055.   --| return s1 < value(s2).
  10056.   --|
  10057.   --| Exceptions (none)
  10058.   --| Notes (none)
  10059.  
  10060.   -- ...............................................
  10061.   -- .                                             .
  10062.   -- .  STRING_PKG."<="                            .  SPEC
  10063.   -- .                                             .
  10064.   -- ...............................................
  10065.   function "<=" (S1, S2: in STRING_TYPE) return BOOLEAN;
  10066.   --| Purpose 
  10067.   --| Lexicographic comparison according to the current comparison_option;
  10068.   --| return value(s1) <= value(s2).
  10069.   --|
  10070.   --| Exceptions (none)
  10071.   --| Notes (none)
  10072.  
  10073.   -- ...............................................
  10074.   -- .                                             .
  10075.   -- .  STRING_PKG."<="                            .  SPEC
  10076.   -- .                                             .
  10077.   -- ...............................................
  10078.   function "<=" (S1: in STRING_TYPE; S2: in STRING) return BOOLEAN;
  10079.   --| Purpose 
  10080.   --| Lexicographic comparison according to the current comparison_option;
  10081.   --| return value(s1) <= s2.
  10082.   --|
  10083.   --| Exceptions (none)
  10084.   --| Notes (none)
  10085.  
  10086.   -- ...............................................
  10087.   -- .                                             .
  10088.   -- .  STRING_PKG."<="                            .  SPEC
  10089.   -- .                                             .
  10090.   -- ...............................................
  10091.   function "<=" (S1: in STRING; S2: in STRING_TYPE) return BOOLEAN;
  10092.   --| Purpose 
  10093.   --| Lexicographic comparison according to the current comparison_option;
  10094.   --| return s1 <= value(s2).
  10095.   --|
  10096.   --| Exceptions (none)
  10097.   --| Notes (none)
  10098.  
  10099.   -- ...............................................
  10100.   -- .                                             .
  10101.   -- .  STRING_PKG.MATCH_C                         .  SPEC
  10102.   -- .                                             .
  10103.   -- ...............................................
  10104.   function Match_C (S     : in STRING_TYPE;
  10105.                     C     : in CHARACTER;
  10106.                     Start : in POSITIVE := 1) return NATURAL;
  10107.   --| Purpose
  10108.   --| Return the minimum index, i in start..length(s), such that
  10109.   --| fetch(s, i) = c.  Returns 0 if no such i exists, 
  10110.   --| including the case where is_empty(s).
  10111.   --|
  10112.   --| Exceptions (none)
  10113.   --| Notes (none)
  10114.  
  10115.   -- ...............................................
  10116.   -- .                                             .
  10117.   -- .  STRING_PKG.MATCH_NOT_C                     .  SPEC
  10118.   -- .                                             .
  10119.   -- ...............................................
  10120.   function Match_Not_C (S     : in STRING_TYPE;
  10121.                         C     : in CHARACTER;
  10122.                         Start : in POSITIVE := 1) return NATURAL;
  10123.   --| Purpose
  10124.   --| Return the minimum index, i in start..length(s), such that
  10125.   --| fetch(s, i) /= c.  Returns 0 if no such i exists,
  10126.   --| including the case where is_empty(s).
  10127.   --|
  10128.   --| Exceptions (none)
  10129.   --| Notes (none)
  10130.  
  10131.   -- ...............................................
  10132.   -- .                                             .
  10133.   -- .  STRING_PKG.MATCH_S                         .  SPEC
  10134.   -- .                                             .
  10135.   -- ...............................................
  10136.   function Match_S (S1, S2: in STRING_TYPE; Start: in POSITIVE := 1)
  10137.       return natural;
  10138.   --| Purpose
  10139.   --| Return the minimum index, i, in start..length(s1), such that,
  10140.   --| for all j in 1..length(s2), fetch(s2, j) = fetch(s1, i + j - 1).
  10141.   --| This is the position of the substring, s2, in s1.
  10142.   --| Returns 0 if no such i exists, including the cases
  10143.   --| where is_empty(s1) or is_empty(s2).
  10144.   --| Note that equal(substr(s1, match_s(s1, s2, i), length(s2)), s2)
  10145.   --| holds, providing that match_s does not raise an exception.
  10146.   --|
  10147.   --| Exceptions (none)
  10148.   --| Notes (none)
  10149.  
  10150.   -- ...............................................
  10151.   -- .                                             .
  10152.   -- .  STRING_PKG.MATCH_S                         .  SPEC
  10153.   -- .                                             .
  10154.   -- ...............................................
  10155.   function Match_S (S1    : in STRING_TYPE;
  10156.                     S2    : in STRING;
  10157.                     Start : in POSITIVE := 1) return NATURAL;
  10158.   --| Purpose
  10159.   --| Return the minimum index, i, in start..length(s1), such that,
  10160.   --| for all j in s2'range, s2(j) = fetch(s1, i + j - 1).
  10161.   --| This is the position of the substring, s2, in s1.
  10162.   --| Returns 0 if no such i exists, including the cases
  10163.   --| where is_empty(s1) or s2 = "".
  10164.   --| Note that equal(substr(s1, match_s(s1, s2, i), s2'length), s2)
  10165.   --| holds, providing that match_s does not raise an exception.
  10166.   --|
  10167.   --| Exceptions (none)
  10168.   --| Notes (none)
  10169.  
  10170.   -- ...............................................
  10171.   -- .                                             .
  10172.   -- .  STRING_PKG.MATCH_ANY                       .  SPEC
  10173.   -- .                                             .
  10174.   -- ...............................................
  10175.   function Match_Any (S, Any : in STRING_TYPE;
  10176.                       Start  : in POSITIVE := 1) return NATURAL;
  10177.   --| Purpose
  10178.   --| Return the minimum index, i in start..length(s), such that
  10179.   --| fetch(s, i) = fetch(any, j), for some j in 1..length(any).
  10180.   --| Raises any_empty if is_empty(any).
  10181.   --| Otherwise, returns 0 if no such i exists, including the case
  10182.   --| where is_empty(s).
  10183.   --|
  10184.   --| Exceptions
  10185.   --|   any_empty
  10186.   --|
  10187.   --| Notes (none)
  10188.  
  10189.   -- ...............................................
  10190.   -- .                                             .
  10191.   -- .  STRING_PKG.MATCH_ANY                       .  SPEC
  10192.   -- .                                             .
  10193.   -- ...............................................
  10194.   function Match_Any (S     : in STRING_TYPE;
  10195.                       Any   : in STRING;
  10196.                       Start : in POSITIVE := 1) return NATURAL;
  10197.   --| Purpose
  10198.   --| Return the minimum index, i, in start..length(s), such that
  10199.   --| fetch(s, i) = any(j), for some j in any'range.
  10200.   --| Raises any_empty if any = "".
  10201.   --| Otherwise, returns 0 if no such i exists, including the case
  10202.   --| where is_empty(s).
  10203.   --|
  10204.   --| Exceptions
  10205.   --|   any_empty
  10206.   --|
  10207.   --| Notes (none)
  10208.  
  10209.   -- ...............................................
  10210.   -- .                                             .
  10211.   -- .  STRING_PKG.MATCH_NONE                      .  SPEC
  10212.   -- .                                             .
  10213.   -- ...............................................
  10214.   function Match_None (S, None : in STRING_TYPE;
  10215.                        Start   : in POSITIVE := 1) return NATURAL;
  10216.   --| Purpose
  10217.   --| Return the minimum index, i in start..length(s), such that
  10218.   --| fetch(s, i) /= fetch(none, j) for each j in 1..length(none).
  10219.   --| If (not is_empty(s)) and is_empty(none), then i is 1.
  10220.   --| Returns 0 if no such i exists, including the case
  10221.   --| where is_empty(s).
  10222.   --|
  10223.   --| Exceptions (none)
  10224.   --| Notes (none)
  10225.  
  10226.   -- ...............................................
  10227.   -- .                                             .
  10228.   -- .  STRING_PKG.MATCH_NONE                      .  SPEC
  10229.   -- .                                             .
  10230.   -- ...............................................
  10231.   function Match_None (S     : in STRING_TYPE;
  10232.                        None  : in STRING;
  10233.                        Start : in POSITIVE := 1) return NATURAL;
  10234.   --| Purpose
  10235.   --| Return the minimum index, i in start..length(s), such that
  10236.   --| fetch(s, i) /= none(j) for each j in none'range.
  10237.   --| If not is_empty(s) and none = "", then i is 1.
  10238.   --| Returns 0 if no such i exists, including the case
  10239.   --| where is_empty(s).
  10240.   --|
  10241.   --| Exceptions (none)
  10242.   --| Notes (none)
  10243.  
  10244. private
  10245.  
  10246.     type STRING_TYPE is access STRING;
  10247.       -- Abstract data type, STRING_TYPE, is a constant sequence of chars
  10248.       -- of arbitrary length.  Representation type is access string.
  10249.       -- It is important to distinguish between an object of the rep type
  10250.       -- and its value; for an object, r, val(r) denotes the value.
  10251.       --
  10252.       -- Representation Invariant:  I: rep --> boolean
  10253.       -- I(r: rep) = (val(r) = null) or else
  10254.       --             (val(r).all'first = 1 &
  10255.       --              val(r).all'last >= 0 &
  10256.       --              (for all r2, val(r) = val(r2) /= null => r is r2))
  10257.       --
  10258.       -- Abstraction Function:  A: rep --> STRING_TYPE
  10259.       -- A(r: rep) = if r = null then
  10260.       --                 the empty sequence
  10261.       --             elsif r'last = 0 then  
  10262.       --                 the empty sequence
  10263.       --             else
  10264.       --                 the sequence consisting of r(1),...,r(r'last).
  10265.  
  10266. end String_Pkg;
  10267. --::::::::::
  10268. --sscan.spc
  10269. --::::::::::
  10270. -- **********************************************
  10271. -- *                                            *
  10272. -- *  STRING_SCANNER                            *  SPEC
  10273. -- *                                            *
  10274. -- **********************************************
  10275. with String_Pkg;
  10276. use String_Pkg;
  10277. package String_Scanner is
  10278. --| Purpose
  10279. --| Functions for scanning tokens from strings.
  10280. --|
  10281. --| This package provides a set of functions used to scan tokens from
  10282. --| strings.  After the function make_Scanner is called to convert a string
  10283. --| into a string Scanner, the rest of the functions may be called to scan
  10284. --| various tokens from the string.
  10285. --|
  10286. --| Initialization Exceptions (none)
  10287. --| Notes (none)
  10288. --| Modifications
  10289. --| Source: Bill Toscano and Michael Gordon, Intermetrics
  10290.  
  10291.   type SCANNER is private;
  10292.  
  10293.   Out_Of_Bounds : exception;
  10294.       -- Raised when a operation is attempted on a
  10295.       -- Scanner that has passed the end
  10296.   Scanner_Already_Marked : exception;
  10297.       -- Raised when a Mark is attemped on a Scanner
  10298.       -- that has already been marked
  10299.  
  10300.   -- ..............................................
  10301.   -- .                                            .
  10302.   -- . STRING_SCANNER.MAKE_SCANNER                .  SPEC
  10303.   -- .                                            .
  10304.   -- ..............................................
  10305.   function Make_Scanner (S : in STRING_TYPE) return SCANNER;
  10306.   --| Purpose
  10307.   --| Construct a Scanner from S.
  10308.   --|
  10309.   --| Exceptions (none)
  10310.   --| Notes (none)
  10311.  
  10312.   -- ..............................................
  10313.   -- .                                            .
  10314.   -- . STRING_SCANNER.DESTROY_SCANNER             .  SPEC
  10315.   -- .                                            .
  10316.   -- ..............................................
  10317.   procedure Destroy_Scanner (T : in out SCANNER);
  10318.   --| Purpose
  10319.   --| Free space occupied by the Scanner.
  10320.   --|
  10321.   --| Exceptions (none)
  10322.   --| Notes (none)
  10323.  
  10324.   -- ..............................................
  10325.   -- .                                            .
  10326.   -- . STRING_SCANNER.MORE                        .  SPEC
  10327.   -- .                                            .
  10328.   -- ..............................................
  10329.   function More (T : in SCANNER) return BOOLEAN;
  10330.   --| Purpose
  10331.   --| Return TRUE iff additional characters remain to be scanned.
  10332.   --|
  10333.   --| Exceptions (none)
  10334.   --| Notes (none)
  10335.  
  10336.   -- ..............................................
  10337.   -- .                                            .
  10338.   -- . STRING_SCANNER.FORWARD                     .  SPEC
  10339.   -- .                                            .
  10340.   -- ..............................................
  10341.   procedure Forward (T : in SCANNER);
  10342.   --| Purpose
  10343.   --| Advance the scanner position.
  10344.   --|
  10345.   --| Exceptions (none)
  10346.   --| Notes (none)
  10347.  
  10348.   -- ..............................................
  10349.   -- .                                            .
  10350.   -- . STRING_SCANNER.BACKWARD                    .  SPEC
  10351.   -- .                                            .
  10352.   -- ..............................................
  10353.   procedure Backward (T : in SCANNER);
  10354.   --| Purpose
  10355.   --| Bump back the scanner position.
  10356.   --|
  10357.   --| Exceptions (none)
  10358.   --| Notes (none)
  10359.  
  10360.   -- ..............................................
  10361.   -- .                                            .
  10362.   -- . STRING_SCANNER.GET                         .  SPEC
  10363.   -- .                                            .
  10364.   -- ..............................................
  10365.   function Get (T : in SCANNER) return CHARACTER;
  10366.   --| Purpose
  10367.   --| Return character at the current Scanner position.
  10368.   --| The scanner position remains unchanged.
  10369.   --|
  10370.   --| Exceptions
  10371.   --|   Out_Of_Bounds
  10372.   --|
  10373.   --| Notes (none)
  10374.  
  10375.   -- ..............................................
  10376.   -- .                                            .
  10377.   -- . STRING_SCANNER.NEXT                        .  SPEC
  10378.   -- .                                            .
  10379.   -- ..............................................
  10380.   procedure Next (T : in     SCANNER;
  10381.                   C :    out CHARACTER);
  10382.   --| Purpose
  10383.   --| Return character at the current Scanner position and update
  10384.   --| the position.
  10385.   --|
  10386.   --| Exceptions
  10387.   --|   Out_Of_Bounds
  10388.   --|
  10389.   --| Notes (none)
  10390.  
  10391.   -- ..............................................
  10392.   -- .                                            .
  10393.   -- . STRING_SCANNER.POSITION                    .  SPEC
  10394.   -- .                                            .
  10395.   -- ..............................................
  10396.   function Position (T : in SCANNER) return POSITIVE;
  10397.   --| Purpose
  10398.   --| Return a positive integer indicating the current Scanner position,
  10399.   --|
  10400.   --| Exceptions
  10401.   --|   Out_Of_Bounds
  10402.   --|
  10403.   --| Notes (none)
  10404.  
  10405.   -- ..............................................
  10406.   -- .                                            .
  10407.   -- . STRING_SCANNER.GET_STRING                  .  SPEC
  10408.   -- .                                            .
  10409.   -- ..............................................
  10410.   function Get_String (T : in SCANNER) return STRING_TYPE;
  10411.   --| Purpose
  10412.   --| Return a String_Type corresponding to the contents of the Scanner
  10413.   --|
  10414.   --| Exceptions (none)
  10415.   --| Notes (none)
  10416.  
  10417.   -- ..............................................
  10418.   -- .                                            .
  10419.   -- . STRING_SCANNER.GET_REMAINDER               .  SPEC
  10420.   -- .                                            .
  10421.   -- ..............................................
  10422.   function Get_Remainder (T : in SCANNER) return STRING_TYPE;
  10423.   --| Purpose
  10424.   --| Return a String_Type starting at the current index of the Scanner
  10425.   --|
  10426.   --| Exceptions (none)
  10427.   --| Notes (none)
  10428.  
  10429.   -- ..............................................
  10430.   -- .                                            .
  10431.   -- . STRING_SCANNER.MARK                        .  SPEC
  10432.   -- .                                            .
  10433.   -- ..............................................
  10434.   procedure Mark (T : in SCANNER);
  10435.   --| Purpose
  10436.   --| Mark the current index for possible future use.
  10437.   --|
  10438.   --| Exceptions
  10439.   --|   Scanner_Already_Marked
  10440.   --|
  10441.   --| Notes (none)
  10442.  
  10443.   -- ..............................................
  10444.   -- .                                            .
  10445.   -- . STRING_SCANNER.RESTORE                     .  SPEC
  10446.   -- .                                            .
  10447.   -- ..............................................
  10448.   procedure Restore (T : in SCANNER);
  10449.   --| Purpose
  10450.   --| Restore the index to the previously marked value
  10451.   --|
  10452.   --| Exceptions (none)
  10453.   --| Notes (none)
  10454.  
  10455.   -- ..............................................
  10456.   -- .                                            .
  10457.   -- . STRING_SCANNER.IS_WORD                     .  SPEC
  10458.   -- .                                            .
  10459.   -- ..............................................
  10460.   function Is_Word (T : in SCANNER) return BOOLEAN;
  10461.   --| Purpose
  10462.   --| Return TRUE iff Scanner is at the start of a word.
  10463.   --|
  10464.   --| Exceptions (none)
  10465.   --| Notes (none)
  10466.  
  10467.   -- ..............................................
  10468.   -- .                                            .
  10469.   -- . STRING_SCANNER.SCAN_WORD                   .  SPEC
  10470.   -- .                                            .
  10471.   -- ..............................................
  10472.   procedure Scan_word (T      : in SCANNER;
  10473.                        Found  : out BOOLEAN;
  10474.                        Result : out STRING_TYPE;
  10475.                        Skip   : in BOOLEAN := FALSE);
  10476.   --| Purpose
  10477.   --| Scan T for a sequence of non-blank 
  10478.   --| characters.  If at least one is found, return Found => TRUE, 
  10479.   --| Result => <the characters>.
  10480.   --| Otherwise return Found => FALSE and Result is unpredictable.
  10481.   --|
  10482.   --| Exceptions (none)
  10483.   --| Notes (none)
  10484.  
  10485.   -- ..............................................
  10486.   -- .                                            .
  10487.   -- . STRING_SCANNER.IS_NUMBER                   .  SPEC
  10488.   -- .                                            .
  10489.   -- ..............................................
  10490.   function Is_Number (T : in SCANNER) return BOOLEAN;
  10491.   --| Purpose
  10492.   --| Return TRUE iff Scan_Number would return a non-null string (Scanner is
  10493.   --| at a decimal digit).
  10494.   --|
  10495.   --| Exceptions (none)
  10496.   --| Notes (none)
  10497.  
  10498.   -- ..............................................
  10499.   -- .                                            .
  10500.   -- . STRING_SCANNER.SCAN_NUMBER                 .  SPEC
  10501.   -- .                                            .
  10502.   -- ..............................................
  10503.   procedure Scan_Number (T      : in SCANNER;
  10504.                          Found  : out BOOLEAN;
  10505.                          Result : out STRING_TYPE;
  10506.                          Skip   : in BOOLEAN := FALSE);
  10507.   --| Purpose
  10508.   --| Scan T for a sequence of digits.
  10509.   --| If at least one is found, return Found => TRUE, Result => <the digits>.
  10510.   --| Otherwise return Found => FALSE and Result is unpredictable.
  10511.   --|
  10512.   --| Exceptions (none)
  10513.   --| Notes (none)
  10514.  
  10515.   -- ..............................................
  10516.   -- .                                            .
  10517.   -- . STRING_SCANNER.SCAN_NUMBER                 .  SPEC
  10518.   -- .                                            .
  10519.   -- ..............................................
  10520.   procedure Scan_Number (T      : in SCANNER;
  10521.                          Found  : out BOOLEAN;
  10522.                          Result : out INTEGER;
  10523.                          Skip   : in BOOLEAN := FALSE);
  10524.   --| Purpose
  10525.   --| Scan T for a sequence of digits.
  10526.   --| If at least one is found, return Found => TRUE, Result => <the digits>.
  10527.   --| Otherwise return Found => FALSE and Result is unpredictable.
  10528.   --|
  10529.   --| Exceptions (none)
  10530.   --| Notes (none)
  10531.  
  10532.   -- ..............................................
  10533.   -- .                                            .
  10534.   -- . STRING_SCANNER.IS_SIGNED_NUMBER            .  SPEC
  10535.   -- .                                            .
  10536.   -- ..............................................
  10537.   function Is_Signed_Number (T : in SCANNER) return BOOLEAN;
  10538.   --| Purpose
  10539.   --| Return TRUE iff Scan_Signed_Number would return a non-null
  10540.   --| string and Scanner is at a decimal digit or sign (+/-).
  10541.   --|
  10542.   --| Exceptions (none)
  10543.   --| Notes (none)
  10544.  
  10545.   -- ..............................................
  10546.   -- .                                            .
  10547.   -- . STRING_SCANNER.SCAN_SIGNED_NUMBER          .  SPEC
  10548.   -- .                                            .
  10549.   -- ..............................................
  10550.   procedure Scan_Signed_Number (T      : in SCANNER;
  10551.                                 Found  : out BOOLEAN;
  10552.                                 Result : out STRING_TYPE;
  10553.                                 Skip   : in BOOLEAN := FALSE);
  10554.   --| Purpose
  10555.   --| Scan T for a sequence of digits preceeded with optional sign.
  10556.   --| If at least one digit is found, return Found => TRUE, 
  10557.   --| Result => <the digits>.
  10558.   --| Otherwise return Found => FALSE and Result is unpredictable.
  10559.   --|
  10560.   --| Exceptions (none)
  10561.   --| Notes (none)
  10562.  
  10563.   -- ..............................................
  10564.   -- .                                            .
  10565.   -- . STRING_SCANNER.SCAN_SIGNED_NUMBER          .  SPEC
  10566.   -- .                                            .
  10567.   -- ..............................................
  10568.   procedure Scan_Signed_Number (T      : in SCANNER;
  10569.                                 Found  : out BOOLEAN;
  10570.                                 Result : out INTEGER;
  10571.                                 Skip   : in BOOLEAN := FALSE);
  10572.   --| Purpose
  10573.   --| Scan T for a sequence of digits preceeded with optional sign.
  10574.   --| If at least one digit is found, return Found => TRUE, 
  10575.   --| Result => <the digits>.
  10576.   --| Otherwise return Found => FALSE and Result is unpredictable.
  10577.   --|
  10578.   --| Exceptions (none)
  10579.   --| Notes (none)
  10580.  
  10581.   -- ..............................................
  10582.   -- .                                            .
  10583.   -- . STRING_SCANNER.IS_SPACE                    .  SPEC
  10584.   -- .                                            .
  10585.   -- ..............................................
  10586.   function Is_Space (T : in SCANNER) return BOOLEAN;
  10587.   --| Purpose
  10588.   --| Return TRUE iff Scan_Space would return a non-null string.
  10589.   --|
  10590.   --| Exceptions (none)
  10591.   --| Notes (none)
  10592.  
  10593.   -- ..............................................
  10594.   -- .                                            .
  10595.   -- . STRING_SCANNER.SCAN_SPACE                  .  SPEC
  10596.   -- .                                            .
  10597.   -- ..............................................
  10598.   procedure Scan_Space (T      : in SCANNER;
  10599.                         Found  : out BOOLEAN;
  10600.                         Result : out STRING_TYPE);
  10601.   --| Purpose
  10602.   --| Scan T past all white space (spaces
  10603.   --| and tabs.  If at least one is found, return Found => TRUE,
  10604.   --| Result => <the characters>.
  10605.   --| Otherwise return Found => FALSE and Result is unpredictable.
  10606.   --|
  10607.   --| Exceptions (none)
  10608.   --| Notes (none)
  10609.  
  10610.   -- ..............................................
  10611.   -- .                                            .
  10612.   -- . STRING_SCANNER.SKIP_SPACE                  .  SPEC
  10613.   -- .                                            .
  10614.   -- ..............................................
  10615.   procedure Skip_Space (T : in SCANNER);
  10616.   --| Purpose
  10617.   --| Scan T past all white space (spaces and tabs).  
  10618.   --|
  10619.   --| Exceptions (none)
  10620.   --| Notes (none)
  10621.  
  10622.   -- ..............................................
  10623.   -- .                                            .
  10624.   -- . STRING_SCANNER.IS_ADA_ID                   .  SPEC
  10625.   -- .                                            .
  10626.   -- ..............................................
  10627.   function Is_Ada_Id (T : in SCANNER) return BOOLEAN;
  10628.   --| Purpose
  10629.   --| Return TRUE iff Scan_Ada_Id would return a non-null string.
  10630.   --|
  10631.   --| Exceptions (none)
  10632.   --| Notes (none)
  10633.  
  10634.   -- ..............................................
  10635.   -- .                                            .
  10636.   -- . STRING_SCANNER.SCAN_ADA_ID                 .  SPEC
  10637.   -- .                                            .
  10638.   -- ..............................................
  10639.   procedure Scan_Ada_Id (T      : in SCANNER;
  10640.                          Found  : out BOOLEAN;
  10641.                          Result : out STRING_TYPE;
  10642.                          Skip   : in BOOLEAN := FALSE);
  10643.   --| Purpose
  10644.   --| Scan T for a valid Ada identifier.
  10645.   --| If one is found, return Found => TRUE, Result => <the characters>.
  10646.   --| Otherwise return Found => FALSE and Result is unpredictable.
  10647.   --|
  10648.   --| Exceptions (none)
  10649.   --| Notes (none)
  10650.  
  10651.   -- ..............................................
  10652.   -- .                                            .
  10653.   -- . STRING_SCANNER.IS_QUOTED                   .  SPEC
  10654.   -- .                                            .
  10655.   -- ..............................................
  10656.   function Is_Quoted (T : in SCANNER) return BOOLEAN;
  10657.   --| Purpose
  10658.   --| Return TRUE iff T is at a quoted string (eg. ... "Hello" ...).
  10659.   --|
  10660.   --| Exceptions (none)
  10661.   --| Notes (none)
  10662.  
  10663.   -- ..............................................
  10664.   -- .                                            .
  10665.   -- . STRING_SCANNER.SCAN_QUOTED                 .  SPEC
  10666.   -- .                                            .
  10667.   -- ..............................................
  10668.   procedure Scan_Quoted (T      : in SCANNER;
  10669.                          Found  : out BOOLEAN;
  10670.                          Result : out STRING_TYPE;
  10671.                          Skip   : in BOOLEAN := FALSE);
  10672.   --| Purpose
  10673.   --| Scan at T for an opening quote
  10674.   --| followed by a sequence of characters and ending with a closing
  10675.   --| quote.  If successful, return Found => TRUE, Result => <the characters>.
  10676.   --| Otherwise return Found => FALSE and Result is unpredictable.
  10677.   --| A pair of quotes within the quoted string is converted to a single quote.
  10678.   --| The outer quotes are stripped. 
  10679.   --|
  10680.   --| Exceptions (none)
  10681.   --| Notes (none)
  10682.  
  10683.   -- ..............................................
  10684.   -- .                                            .
  10685.   -- . STRING_SCANNER.IS_ENCLOSED                 .  SPEC
  10686.   -- .                                            .
  10687.   -- ..............................................
  10688.   function Is_Enclosed (B : in CHARACTER;
  10689.                         E : in CHARACTER;
  10690.                         T : in SCANNER) return BOOLEAN;
  10691.   --| Purpose
  10692.   --| Return TRUE iff T as encosed by B and E (eg. ... [ABC] ...).
  10693.   --|
  10694.   --| Exceptions (none)
  10695.   --| Notes (none)
  10696.  
  10697.   -- ..............................................
  10698.   -- .                                            .
  10699.   -- . STRING_SCANNER.SCAN_ENCLOSED               .  SPEC
  10700.   -- .                                            .
  10701.   -- ..............................................
  10702.   procedure Scan_Enclosed (B      : in CHARACTER;
  10703.                            E      : in CHARACTER;
  10704.                            T      : in SCANNER;
  10705.                            Found  : out BOOLEAN;
  10706.                            Result : out STRING_TYPE;
  10707.                            Skip   : in BOOLEAN := FALSE);
  10708.   --| Purpose
  10709.   --| Scan at T for an enclosing character
  10710.   --| followed by a sequence of characters and ending with an enclosing character.
  10711.   --| If successful, return Found => TRUE, Result => <the characters>.
  10712.   --| Otherwise return Found => FALSE and Result is unpredictable.
  10713.   --| The enclosing characters are stripped. 
  10714.   --|
  10715.   --| Exceptions (none)
  10716.   --| Notes (none)
  10717.  
  10718.   -- ..............................................
  10719.   -- .                                            .
  10720.   -- . STRING_SCANNER.IS_SEQUENCE                 .  SPEC
  10721.   -- .                                            .
  10722.   -- ..............................................
  10723.   function Is_Sequence (Chars : in STRING_TYPE;
  10724.                         T     : in SCANNER) return BOOLEAN;
  10725.   --| Purpose
  10726.   --| Return TRUE iff T is at some character of Chars.
  10727.   --|
  10728.   --| Exceptions (none)
  10729.   --| Notes (none)
  10730.  
  10731.   -- ..............................................
  10732.   -- .                                            .
  10733.   -- . STRING_SCANNER.IS_SEQUENCE                 .  SPEC
  10734.   -- .                                            .
  10735.   -- ..............................................
  10736.   function Is_Sequence (Chars : in STRING;
  10737.                         T     : in SCANNER) return BOOLEAN;
  10738.   --| Purpose
  10739.   --| Return TRUE iff T is at some character of Chars.
  10740.   --|
  10741.   --| Exceptions (none)
  10742.   --| Notes (none)
  10743.  
  10744.   -- ..............................................
  10745.   -- .                                            .
  10746.   -- . STRING_SCANNER.SCAN_SEQUENCE               .  SPEC
  10747.   -- .                                            .
  10748.   -- ..............................................
  10749.   procedure Scan_Sequence (Chars  : in STRING_TYPE;
  10750.                            T      : in SCANNER;
  10751.                            Found  : out BOOLEAN;
  10752.                            Result : out STRING_TYPE;
  10753.                            Skip   : in BOOLEAN := FALSE);
  10754.   --| Purpose
  10755.   --| Scan T for a sequence of characters C such that C appears in 
  10756.   --| Char.  If at least one is found, return Found => TRUE, 
  10757.   --| Result => <the characters>.
  10758.   --| Otherwise return Found => FALSE and Result is unpredictable.
  10759.   --| Skip means to skip white characters before scanning.
  10760.   --|
  10761.   --| Exceptions (none)
  10762.   --|
  10763.   --| Notes
  10764.   --| Scan_Sequence("0123456789", S, Index, Found, Result)
  10765.   --| is equivalent to Scan_Number(S, Index, Found, Result)
  10766.   --| but is less efficient.
  10767.  
  10768.   -- ..............................................
  10769.   -- .                                            .
  10770.   -- . STRING_SCANNER.SCAN_SEQUENCE               .  SPEC
  10771.   -- .                                            .
  10772.   -- ..............................................
  10773.   procedure Scan_Sequence (Chars  : in STRING;
  10774.                            T      : in SCANNER;
  10775.                            Found  : out BOOLEAN;
  10776.                            Result : out STRING_TYPE;
  10777.                            Skip   : in BOOLEAN := FALSE);
  10778.   --| Purpose
  10779.   --| Scan T for a sequence of characters C such that C appears in 
  10780.   --| Char.  If at least one is found, return Found => TRUE, 
  10781.   --| Result => <the characters>.
  10782.   --| Otherwise return Found => FALSE and Result is unpredictable.
  10783.   --| Skip means to skip white characters before scanning.
  10784.   --|
  10785.   --| Exceptions (none)
  10786.   --|
  10787.   --| Notes
  10788.   --| Scan_Sequence("0123456789", S, Index, Found, Result)
  10789.   --| is equivalent to Scan_Number(S, Index, Found, Result)
  10790.   --| but is less efficient.
  10791.  
  10792.   -- ..............................................
  10793.   -- .                                            .
  10794.   -- . STRING_SCANNER.IS_NOT_SEQUENCE             .  SPEC
  10795.   -- .                                            .
  10796.   -- ..............................................
  10797.   function Is_Not_Sequence (Chars : in STRING_TYPE;
  10798.                             T     : in SCANNER) return BOOLEAN;
  10799.   --| Purpose
  10800.   --| Return TRUE iff T is not at some character of Chars.
  10801.   --|
  10802.   --| Exceptions (none)
  10803.   --| Notes (none)
  10804.  
  10805.   -- ..............................................
  10806.   -- .                                            .
  10807.   -- . STRING_SCANNER.IS_NOT_SEQUENCE             .  SPEC
  10808.   -- .                                            .
  10809.   -- ..............................................
  10810.   function Is_Not_Sequence (Chars : in STRING;
  10811.                             T     : in SCANNER) return BOOLEAN;
  10812.   --| Purpose
  10813.   --| Return TRUE iff T is not at some character of Chars.
  10814.   --|
  10815.   --| Exceptions (none)
  10816.   --| Notes (none)
  10817.  
  10818.   -- ..............................................
  10819.   -- .                                            .
  10820.   -- . STRING_SCANNER.SCAN_NOT_SEQUENCE           .  SPEC
  10821.   -- .                                            .
  10822.   -- ..............................................
  10823.   procedure Scan_Not_Sequence (Chars  : in STRING_TYPE;
  10824.                                T      : in SCANNER;
  10825.                                Found  : out BOOLEAN;
  10826.                                Result : out STRING_TYPE;
  10827.                                Skip   : in BOOLEAN := FALSE);
  10828.   --| Purpose
  10829.   --| Scan T for a sequence of characters C such that C does not appear
  10830.   --| in Chars.  If at least one such C is found, return Found => TRUE, 
  10831.   --| Result => <the characters>.
  10832.   --| Otherwise return Found => FALSE and Result is unpredictable.
  10833.   --| Skip means to skip white characters before scanning.
  10834.   --|
  10835.   --| Exceptions (none)
  10836.   --| Notes (none)
  10837.  
  10838.   -- ..............................................
  10839.   -- .                                            .
  10840.   -- . STRING_SCANNER.SCAN_NOT_SEQUENCE           .  SPEC
  10841.   -- .                                            .
  10842.   -- ..............................................
  10843.   procedure Scan_Not_Sequence (Chars  : in STRING;
  10844.                                T      : in SCANNER;
  10845.                                Found  : out BOOLEAN;
  10846.                                Result : out STRING_TYPE;
  10847.                                Skip   : in BOOLEAN := FALSE);
  10848.   --| Purpose
  10849.   --| Scan T for a sequence of characters C such that C does not appear
  10850.   --| in Chars.  If at least one such C is found, return Found => TRUE, 
  10851.   --| Result => <the characters>.
  10852.   --| Otherwise return Found => FALSE and Result is unpredictable.
  10853.   --| Skip means to skip white characters before scanning.
  10854.   --|
  10855.   --| Exceptions (none)
  10856.   --| Notes (none)
  10857.  
  10858.   -- ..............................................
  10859.   -- .                                            .
  10860.   -- . STRING_SCANNER.IS_LITERAL                  .  SPEC
  10861.   -- .                                            .
  10862.   -- ..............................................
  10863.   function Is_Literal (Chars : in STRING_TYPE;
  10864.                        T     : in SCANNER) return BOOLEAN;
  10865.   --| Purpose
  10866.   --| Return TRUE iff T is at literal Chars.
  10867.   --|
  10868.   --| Exceptions (none)
  10869.   --| Notes (none)
  10870.  
  10871.   -- ..............................................
  10872.   -- .                                            .
  10873.   -- . STRING_SCANNER.IS_LITERAL                  .  SPEC
  10874.   -- .                                            .
  10875.   -- ..............................................
  10876.   function Is_Literal (Chars : in STRING;
  10877.                        T     : in SCANNER) return BOOLEAN;
  10878.   --| Purpose
  10879.   --| Return TRUE iff T is at literal Chars.
  10880.   --|
  10881.   --| Exceptions (none)
  10882.   --| Notes (none)
  10883.  
  10884.   -- ..............................................
  10885.   -- .                                            .
  10886.   -- . STRING_SCANNER.SCAN_LITERAL                .  SPEC
  10887.   -- .                                            .
  10888.   -- ..............................................
  10889.   procedure Scan_Literal (Chars  : in STRING_TYPE;
  10890.                           T      : in SCANNER;
  10891.                           Found  : out BOOLEAN;
  10892.                           Skip   : in BOOLEAN := FALSE);
  10893.   --| Purpose
  10894.   --| Scan T for a literal Chars such that Char matches the sequence
  10895.   --| of characters in T.  If found, return Found => TRUE, 
  10896.   --| Otherwise return Found => FALSE
  10897.   --| Skip means to skip white characters before scanning.
  10898.   --|
  10899.   --| Exceptions (none)
  10900.   --| Notes (none)
  10901.  
  10902.   -- ..............................................
  10903.   -- .                                            .
  10904.   -- . STRING_SCANNER.SCAN_LITERAL                .  SPEC
  10905.   -- .                                            .
  10906.   -- ..............................................
  10907.   procedure Scan_Literal (Chars  : in STRING;
  10908.                           T      : in SCANNER;
  10909.                           Found  : out BOOLEAN;
  10910.                           Skip   : in BOOLEAN := FALSE);
  10911.   --| Purpose
  10912.   --| Scan T for a litral Chars such that Char matches the sequence
  10913.   --| of characters in T.  If found, return Found => TRUE, 
  10914.   --| Otherwise return Found => FALSE
  10915.   --| Skip means to skip white characters before scanning.
  10916.   --|
  10917.   --| Exceptions (none)
  10918.   --| Notes (none)
  10919.  
  10920.   -- ..............................................
  10921.   -- .                                            .
  10922.   -- . STRING_SCANNER.IS_NOT_LITERAL              .  SPEC
  10923.   -- .                                            .
  10924.   -- ..............................................
  10925.   function Is_Not_Literal (Chars : in STRING;
  10926.                            T     : in SCANNER) return BOOLEAN;
  10927.   --| Purpose
  10928.   --| Return TRUE iff T is not at literal Chars
  10929.   --|
  10930.   --| Exceptions (none)
  10931.   --| Notes (none)
  10932.  
  10933.   -- ..............................................
  10934.   -- .                                            .
  10935.   -- . STRING_SCANNER.IS_NOT_LITERAL              .  SPEC
  10936.   -- .                                            .
  10937.   -- ..............................................
  10938.   function Is_Not_Literal (Chars : in STRING_TYPE;
  10939.                            T     : in SCANNER) return BOOLEAN;
  10940.   --| Purpose
  10941.   --| Return TRUE iff T is not at literal Chars
  10942.   --|
  10943.   --| Exceptions (none)
  10944.   --| Notes (none)
  10945.  
  10946.   -- ..............................................
  10947.   -- .                                            .
  10948.   -- . STRING_SCANNER.SCAN_NOT_LITERAL            .  SPEC
  10949.   -- .                                            .
  10950.   -- ..............................................
  10951.   procedure Scan_Not_Literal (Chars  : in STRING;
  10952.                               T      : in SCANNER;
  10953.                               Found  : out BOOLEAN;
  10954.                               Result : out STRING_TYPE;
  10955.                               Skip   : in BOOLEAN := FALSE);
  10956.   --| Purpose
  10957.   --| Scan T for a literal Chars such that Char does not match the
  10958.   --| sequence of characters in T.  If found, return Found => TRUE, 
  10959.   --| Otherwise return Found => FALSE
  10960.   --| Skip means to skip white characters before scanning.
  10961.   --|
  10962.   --| Exceptions (none)
  10963.   --| Notes (none)
  10964.  
  10965.   -- ..............................................
  10966.   -- .                                            .
  10967.   -- . STRING_SCANNER.SCAN_NOT_LITERAL            .  SPEC
  10968.   -- .                                            .
  10969.   -- ..............................................
  10970.   procedure Scan_Not_Literal (Chars  : in STRING_TYPE;
  10971.                               T      : in SCANNER;
  10972.                               Found  : out BOOLEAN;
  10973.                               Result : out STRING_TYPE;
  10974.                               Skip   : in BOOLEAN := FALSE);
  10975.   --| Purpose
  10976.   --| Scan T for a litral Chars such that Char does not match the
  10977.   --| sequence of characters in T.  If found, return Found => TRUE, 
  10978.   --| Otherwise return Found => FALSE
  10979.   --| Skip means to skip white characters before scanning.
  10980.   --|
  10981.   --| Exceptions (none)
  10982.   --| Notes (none)
  10983.  
  10984. private
  10985.     type SCAN_RECORD is
  10986.       record
  10987.         Text  : STRING_TYPE;       -- Copy of string being scanned
  10988.         Index : POSITIVE := 1;     -- Current position of Scanner
  10989.         Mark  : NATURAL := 0;      -- Mark
  10990.       end record;
  10991.     type SCANNER is access SCAN_RECORD;
  10992.  
  10993. end String_Scanner;
  10994. --::::::::::
  10995. --tod.spc
  10996. --::::::::::
  10997. -- ****************************************************
  10998. -- *                                                  *
  10999. -- *  TOD_UTILITIES                                   *  SPEC
  11000. -- *                                                  *
  11001. -- ****************************************************
  11002. with Calendar;  -- Predefined (internal representation) TOD package.
  11003. package TOD_Utilities is
  11004. --| Purpose
  11005. --| This package will provide direct conversion from an external
  11006. --| time/date string to the internal Ada CALENDAR.TIME representation
  11007. --| and vice versa.  Most free format external representations are
  11008. --| supported.  Components of an external format include:
  11009. --|   Year, Month and Day (as numbers and strings), Hour, Minutes,
  11010. --|   and Seconds
  11011. --| As long as the external representation can be parsed unambiguously,
  11012. --| this package should be able to handle the conversion.  Examples of
  11013. --| legal external formats:
  11014. --|   7pm Fr March 12, 1982
  11015. --|   15 Dec. 84 12:36PM
  11016. --|   YESTERDAY 3PM
  11017. --|   6/01/83          <-- defaults to 12:00:00AM
  11018. --|   3:45AM           <-- defaults to the current date
  11019. --|   18:07:35         <-- defaults to the current date
  11020. --|   8-26             <-- defaults to 12:00:00AM of the current year
  11021. --|   friday           <-- defaults to 12:00:00AM of the current or next
  11022. --|                        future Friday
  11023. --| Examples of illegal external representations:
  11024. --|   2/31/84          <-- February never has a 31st day
  11025. --|   12:3605/01/84    <-- too tough to parse (nondeterminstic)
  11026. --|   3/8423:00:00     <-- too tough to parse (nondeterminstic)
  11027. --|   3:54:29AMTues    <-- too tough to parse (nondeterminstic)
  11028. --|   Nov 1983         <-- must always include day number in the date
  11029. --|   Sun 8/3/84       <-- 8/3/84 was a Friday
  11030. --|
  11031. --| Optional periods may be placed after ABBREVIATED day/month names.
  11032. --|
  11033. --| All external formats are converted to upper case, so there are no
  11034. --| problems with specifying mixed and/or lower case input.  All
  11035. --| results are returned in upper case by default (which can be overridden
  11036. --| by specifying lower case or mixed case).
  11037. --|
  11038. --| Special external formats: TODAY, TOMORROW, YESTERDAY, NOW
  11039. --| TODAY is equivalent to 12AM of the current date.  TOMORROW and
  11040. --| YESTERDAY are equivalent to the next/previous date.  NOW is
  11041. --| equivalent to calling the function CALENDAR.CLOCK.
  11042. --|
  11043. --| Defaults:
  11044. --|   If the year is omitted, it defaults to the current year.  If the
  11045. --|   time is omitted, it defaults to 12:00:00AM.  If the day name and no
  11046. --|   date is specified, the current or next future date is assumed.  If
  11047. --|   only the time is specified, the current date is assumed.  If the
  11048. --|   minutes and/or seconds are not specified in the time, they default
  11049. --|   to zero.  If the year is given in short format (1 or 2 digits) then
  11050. --|   it defaults to the current century.
  11051. --|
  11052. --| BNF for the external representation:
  11053. --|   {<special_format> [<time>] |
  11054. --|    [<time>] <special_format> |
  11055. --|    <day_string> &|* <date> &|* <time>}
  11056. --|
  11057. --|   <special_format> ::= {TODAY | TOMORROW | YESTERDAY | NOW}
  11058. --|
  11059. --|   <day_string> ::= SU|NDAY, MO|NDAY, ..., SA|TURDAY
  11060. --|
  11061. --|   <date> ::= {<month_number><sep1><day_number>[<sep1><year_number>] |
  11062. --|               <month_name><sep2><day_number>[<sep2><year_number>] |
  11063. --|               <day_number><sep2><month_name>[<sep2><year_number>] |
  11064. --|               <full_year_number><sep2><month_name><sep2><day_number> |
  11065. --|               <full_year_number><sep2><day_number><sep2><month_name>}
  11066. --|
  11067. --|   <time> ::= {<hour>':'<minutes>[':'<seconds>][<AM_PM>] |
  11068. --|               <AMPM_hour><AM_PM>}
  11069. --|
  11070. --|   <month_number> ::= 1 .. 12
  11071. --|   <month_name> ::= JAN|UARY, FEB|RUARY, ..., DEC|EMBER
  11072. --|   <day_number> ::= 1 .. 31
  11073. --|   <year_number> ::= {<short_year_number> | <full_year_number>}
  11074. --|   <short_year_number> ::= [0]0 .. 99    <-- for century 2000
  11075. --|                           [0]1 .. 99    <-- for century 2100
  11076. --|   <full_year_number> ::= 1901 .. 2099
  11077. --|   <sep1> ::= {'-'|'/'}
  11078. --|   <sep2> ::= {<sep1> | {' ' | ','} ...}
  11079. --|
  11080. --|   <hour> ::= [0]0 .. 24
  11081. --|   <AMPM_hour> ::= [0]1 .. 12
  11082. --|   <minutes> ::= 00 .. 59
  11083. --|   <seconds> ::= 00 .. 59
  11084. --|   <AM_PM> ::= {"AM" | "PM"}
  11085. --|
  11086. --|   Notes on the BNF above:
  11087. --|     Items in angle brackets must be separated by at least one
  11088. --|     blank and/or comma when they appear with exactly one space
  11089. --|     between them.
  11090. --|
  11091. --|     However, items in angle brackets which are not separated by
  11092. --|     exactly one blank have a more rigid syntax, and must be followed
  11093. --|     precisely as specified in the BNF.
  11094. --|
  11095. --|     Some characters/strings are enclosed in quotes to emphasize that
  11096. --|     they are explicit, and not metasymbols.  When specifying an
  11097. --|     external TOD_String, do NOT include the quotes.
  11098. --|
  11099. --|     The AM/PM indicator may be left off the time if at least the
  11100. --|     hours and minutes are specified.  If only the hour is specified,
  11101. --|     it must be in the range 01 .. 12 and must have the AM/PM
  11102. --|     indicator following it.  If the AM/PM indicator is left off a
  11103. --|     time format, AM is assumed unless the hour is in the range
  11104. --|     13 .. 23.  If the AM/PM indicator is included, the hour must
  11105. --|     be in the range 01 .. 12.
  11106. --|
  11107. --|     Notation:
  11108. --|       {...|...|...}    -- Select exactly one alternative.
  11109. --|       [...]            -- Optional.
  11110. --|       &|               -- Select one or the other or both,
  11111. --|       &|*              -- Same as &| with the extension of selecting
  11112. --|                           the items in any order.
  11113. --|       ' '              -- Encloses a character literal.
  11114. --|       " "              -- Encloses a string.
  11115. --|       < >              -- Encloses a non-terminal symbol.
  11116. --|       ...              -- Denotes a repeatable field.
  11117. --|       |                -- Separates alternatives and denotes legal
  11118. --|                        -- abbreviations.
  11119. --|
  11120. --| Initialization Exceptions (none)
  11121. --| Notes (none)
  11122. --|
  11123. --| Modifications
  11124. --| Author:  Geoff Mendal, Stanford University
  11125.  
  11126.   External_TOD_Representation_Length : constant POSITIVE := 38;
  11127.   subtype EXTERNAL_TOD_REPRESENTATION_TYPE is STRING (
  11128.     1 .. External_TOD_Representation_Length);
  11129.   -- This type should be used to retrieve an external TOD
  11130.   -- representation from the CALENDAR.TIME representation.
  11131.  
  11132.   type TYPE_SET is (UPPER_CASE, lower_case, Mixed_Case);
  11133.   -- This type should be used to specify the type set of an
  11134.   -- external representation returned by the internal-to-external
  11135.   -- function below.
  11136.  
  11137.   -- ..................................................
  11138.   -- .                                                .
  11139.   -- .  TOD_UTILITIES.VERSION                         .  SPEC
  11140.   -- .                                                .
  11141.   -- ..................................................
  11142.   function Version return STRING;
  11143.   --| Purpose
  11144.   --| Returns the version number of this package.
  11145.   --|
  11146.   --| Exceptions (none)
  11147.   --| Notes (none)
  11148.  
  11149.   -- ....................................................
  11150.   -- .                                                  .
  11151.   -- .  TOD_UTILITIES.CONVERT                           .  SPEC
  11152.   -- .                                                  .
  11153.   -- ....................................................
  11154.   function Convert (
  11155.     TOD_Value       : in CALENDAR.TIME;
  11156.     Default_Setting : in TYPE_SET := UPPER_CASE)
  11157.     return EXTERNAL_TOD_REPRESENTATION_TYPE;
  11158.   --| Purpose
  11159.   --| The following function will take the CALENDAR.TIME representation
  11160.   --| and return an external representation. The external representation
  11161.   --| has the following format:
  11162.   --|   Columns  1 ..  9 : Day as a string
  11163.   --|   Columns 11 .. 12 : Day as a number
  11164.   --|   Columns 14 .. 22 : Month as a string
  11165.   --|   Columns 24 .. 27 : year number
  11166.   --|   Columns 29 .. 38 : time in AM/PM format
  11167.   --|   All unused columns are blank
  11168.   --|
  11169.   --|  Example string returned:
  11170.   --|    "THURSDAY  09 AUGUST    1984 05:19:05PM"
  11171.   --|
  11172.   --| Exceptions (none)
  11173.   --| Notes (none)
  11174.  
  11175.   -- ....................................................
  11176.   -- .                                                  .
  11177.   -- .  TOD_UTILITIES.NOW                               .  SPEC
  11178.   -- .                                                  .
  11179.   -- ....................................................
  11180.   function Now (Default_Setting : in TYPE_SET := UPPER_CASE)
  11181.     return EXTERNAL_TOD_REPRESENTATION_TYPE;
  11182.   --| Purpose
  11183.   --| This function is a convenience, equivalent to calling
  11184.   --| the above Convert function with an argument of
  11185.   --| CALENDAR.CLOCK.  The current time and date are
  11186.   --| returned as specified for Convert above.
  11187.   --|
  11188.   --| Exceptions (none)
  11189.   --| Notes
  11190.   --|    Same as Convert(Calendar.Clock)
  11191.  
  11192.   -- ....................................................
  11193.   -- .                                                  .
  11194.   -- .  TOD_UTILITIES.CONVERT                           .  SPEC
  11195.   -- .                                                  .
  11196.   -- ....................................................
  11197.   function Convert (TOD_String : in STRING) return CALENDAR.TIME;
  11198.   --| Purpose
  11199.   --| This function will take an external TOD representation
  11200.   --| and return the CALENDAR.TIME representation.  The external
  11201.   --| representation can be any STRING object that conforms to
  11202.   --| the BNF given above.
  11203.   --|
  11204.   --| Exceptions (see below)
  11205.   --| Notes (none)
  11206.  
  11207.   Duplication_Error,                          -- "5/25/61 May 25 1961"
  11208.   Date_Error,                                 -- "2/31/75"
  11209.   Month_Number_Error,                         -- "13/1/1960"
  11210.   Year_Error,                                 -- "1/1/1900"
  11211.   Day_Number_Error,                           -- "1/32/1984"
  11212.   Day_Date_Error,                             -- "Sunday 8/3/84"
  11213.   Month_Missing_Error,                        -- "1961 25"
  11214.   Day_Number_Missing_Error,                   -- "1961 May"
  11215.   Hour_Error,                                 -- "25:00:00"
  11216.   Minute_Error,                               -- "23:61:00"
  11217.   Second_Error,                               -- "23:59:60"
  11218.   Time_String_Error,                          -- "1:05:05:PM"
  11219.   Abbreviation_Error,                         -- "Sept.emb. 5"
  11220.   External_Representation_Error : exception;  -- "blah blah blah"
  11221.   -- These exceptions will be raised if the input to the
  11222.   -- above function cannot be parsed unambiguously.  Also, this function
  11223.   -- traps CALENDAR.TIME_ERROR and instead raises the exception
  11224.   -- Date_Error below in its place.
  11225.  
  11226. end TOD_Utilities;
  11227.